chia-chiao ho t oward optimized code generation through model - based optimization 2010/9/24 1 ccu...

28
Chia-Chiao Ho TOWARD OPTIMIZED CODE GENERATION THROUGH MODEL- BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi * Chokri Mraidha * Sébastien Gérard * François Terrier * Pierre Boulet ** *CEA, LIST, Laboratory of model driven engineering for embedded systems ** Université Lille 1, Sciences et Technologies Published on Design, Automation & Test in Europe Conference & Exhibition (DATE), 2010

Upload: naomi-harmon

Post on 18-Jan-2018

218 views

Category:

Documents


0 download

DESCRIPTION

I NTRODUCTION Model-based Development (MBD) Using model to design systems Offer an higher level of abstraction 2010/9/24 3 CCU CSIE ESL Group Meeting Presentation

TRANSCRIPT

Page 1: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

CCU CSIE ESL Group Meeting Presentation

1

Chia-Chiao Ho

TOWARD OPTIMIZED CODE GENERATION THROUGH MODEL-BASED OPTIMIZATION

2010/9/24

Authors:Asma Charfi *Chokri Mraidha *Sébastien Gérard *François Terrier *Pierre Boulet ***CEA, LIST, Laboratory of model driven engineering for embedded systems** Université Lille 1, Sciences et TechnologiesPublished on Design, Automation & Test in Europe Conference & Exhibition (DATE), 2010

Page 2: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

2

CCU CSIE ESL Group Meeting Presentation

OUTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion

2010/9/24

Page 3: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

3

CCU CSIE ESL Group Meeting Presentation

INTRODUCTION Model-based Development (MBD)

Using model to design systemsOffer an higher level of abstraction

2010/9/24

Page 4: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

4

CCU CSIE ESL Group Meeting Presentation

INTRODUCTION (CONT.) Real-Time and Embedded System (RTES)

become more complex and along with limited resources.

With automatic code generation tools, MBD brings: Increasing productivityEnhancing source code consistency Intending to improving the performance

In this paper, we are going to examine the possibility of model-based optimization

2010/9/24

Page 5: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

5

CCU CSIE ESL Group Meeting Presentation

OUTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion

2010/9/24

Page 6: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

6

CCU CSIE ESL Group Meeting Presentation

MODEL-BASED DEVELOPMENT FOR RTES DESIGN 3 Steps to develop a RTES1. Building models

Design with Unified Model Language (UML)2. Code generation

Compile models to C/C++, Java, etc.3. Code Compilation and Optimization

Use GCC Compiler and it’s Optimization Options.

2010/9/24

Page 7: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

7

CCU CSIE ESL Group Meeting Presentation

RAISING THE LEVEL OF ABSTRACTION IN RTES DESIGN With UML, we can describe a basic system

model. But RTES needs more specific descriptions for

modeling and analysis. Modeling and Analysis of Real-Time and

Embedded (MARTE) is an extended profile for UML, using for annotating models with required information

Thus, it’s possible for automatic code generation.

2010/9/24

Page 8: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

8

CCU CSIE ESL Group Meeting Presentation

GENERATING CODE FROM UML MODELS Before adding Activities and Actions

packages into UML2, Designer need to complete the code or it can’t

be compiled. Now it’s possible to make code generation

from UML2 models a fully automatable step.

2010/9/24

Page 9: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

9

CCU CSIE ESL Group Meeting Presentation

COMPILATION AND OPTIMIZATION GCC provides –O1, -O2, -O3 and other

optimization options. In this paper, code size is the optimized

target for RTES. –Os option is used here. Before GCC 4.0, Register transfer language

(RTL) optimization is used. Low level optimization

GCC 4.0 now using Static single assignment (SSA) optimization. High level optimization

2010/9/24

Page 10: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

10

CCU CSIE ESL Group Meeting Presentation

OUTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion

2010/9/24

Page 11: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

11

CCU CSIE ESL Group Meeting Presentation

EXPERIMENTAL STUDIES For showing relying only on compiler

optimizations is not enough. There are two examples later demonstrate

the shortages of compiler optimizations.

2010/9/24

Page 12: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

12

CCU CSIE ESL Group Meeting Presentation

BUILDING STATE MACHINE DIAGRAM This paper uses Papyrus as their tool to

design state machine diagram.

2010/9/24

Page 13: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

13

CCU CSIE ESL Group Meeting Presentation

EXAMPLE 1: NO ENTRY TRANSITION

2010/9/24

Page 14: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

14

CCU CSIE ESL Group Meeting Presentation

EXAMPLE 2: COMPLETION TRANSITION

2010/9/24

Page 15: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

15

CCU CSIE ESL Group Meeting Presentation

GENERATING THE C++ CODE FROM UML STATE MACHINE State Pattern

A state is implemented as a class. State Table Transition

A 2-D table describing the relation between states and events

Nested Switch Case Statement having an outer case statement that selects the

current state and an inner case statement that selects the appropriate behavior given the type of the received event

2010/9/24

Page 16: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

16

CCU CSIE ESL Group Meeting Presentation

COMPILING AND OPTIMIZING THE GENERATED CODE USING GCC With option –Os, GCC is not able to remove

unreachable states. The authors uses a optimization tool to

remove the unreachable states. The first example exists a state with no

incoming transition. The second example shows a completion

transition. Both can’t be optimized by the compiler in

code size

2010/9/24

Page 17: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

17

CCU CSIE ESL Group Meeting Presentation

OPTIMIZED RESULTSRequired Optimization

Code Size(Before)

Code Size(After)

Optimization Rate

Remove unreachable state

12669 bytes 11393 bytes 10.07%

Remove transition originated from state that have a completion transition

48764 bytes 26379 bytes 45.90%

2010/9/24

Page 18: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

18

CCU CSIE ESL Group Meeting Presentation

RESULTS INTERPRETATION The semantics lost in code generation, thus

large improvement after optimizing from model level in 3 implementations.

2010/9/24

Page 19: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

19

CCU CSIE ESL Group Meeting Presentation

OUTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion

2010/9/24

Page 20: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

20

CCU CSIE ESL Group Meeting Presentation

BEFORE CODE GENERATION The model level optimization is higher than

SSA in GCC optimization. The CFG is produced twice before the code

generation and in compilation.

2010/9/24

Page 21: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

21

CCU CSIE ESL Group Meeting Presentation

DURING CODE GENERATION The model debugging is unable to debug

with removed state.

2010/9/24

Page 22: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

22

CCU CSIE ESL Group Meeting Presentation

AFTER CODE GENERATION The UML semantics are visible to the

compiler

2010/9/24

Page 23: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

23

CCU CSIE ESL Group Meeting Presentation

OUTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion

2010/9/24

Page 24: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

24

CCU CSIE ESL Group Meeting Presentation

CONCLUSION Due to the loss of some UML semantics

during the code generation, the GCC is unable to do optimization in MBD way.

The higher model-based optimization is useful in the experiment.

The future work is to develop a complete tool to generate assembly code, instead of high level language. Avoid the unnecessary use of two high level languages.

2010/9/24

Page 25: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

25

CCU CSIE ESL Group Meeting Presentation

THANK YOU FOR YOUR ATTENTION!

2010/9/24

Page 26: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

26

CCU CSIE ESL Group Meeting Presentation

MARTE UML Profile for Modeling and Analysis of Real-

Time and Embedded systems http://www.omgmarte.org/

2010/9/24

Page 27: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

27

CCU CSIE ESL Group Meeting Presentation

CODE GENERATION PATTERNS State Pattern http://en.wikipedia.org/wiki/State_pattern State Transition Table http://en.wikipedia.org/wiki/State_transition_t

able Nested Switch Case Statements http://www.iplab.is.tsukuba.ac.jp/paper/docto

r/niaz_doctor.pdf

2010/9/24

Page 28: Chia-Chiao Ho T OWARD OPTIMIZED CODE GENERATION THROUGH MODEL - BASED OPTIMIZATION 2010/9/24 1 CCU CSIE ESL Group Meeting Presentation Authors: Asma Charfi

28

CCU CSIE ESL Group Meeting Presentation

RTL AND SSA Register transfer language http://en.wikipedia.org/wiki/Register_transfer

_language#RTL_in_GCC Static single assignment http://en.wikipedia.org/wiki/Static_single_assi

gnment_form

2010/9/24