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 * 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
O UTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion 2010/9/24 2 CCU CSIE ESL Group Meeting Presentation
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
I NTRODUCTION ( CONT.) Real-Time and Embedded System (RTES) become more complex and along with limited resources. With automatic code generation tools, MBD brings: Increasing productivity Enhancing 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 4 CCU CSIE ESL Group Meeting Presentation
O UTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion 2010/9/24 5 CCU CSIE ESL Group Meeting Presentation
M ODEL - BASED D EVELOPMENT F OR RTES D ESIGN 3 Steps to develop a RTES 1. 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 6 CCU CSIE ESL Group Meeting Presentation
R AISING 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 7 CCU CSIE ESL Group Meeting Presentation
G ENERATING 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 8 CCU CSIE ESL Group Meeting Presentation
C OMPILATION 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 9 CCU CSIE ESL Group Meeting Presentation
O UTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion 2010/9/24 10 CCU CSIE ESL Group Meeting Presentation
E XPERIMENTAL S TUDIES For showing relying only on compiler optimizations is not enough. There are two examples later demonstrate the shortages of compiler optimizations. 2010/9/24 11 CCU CSIE ESL Group Meeting Presentation
B UILDING STATE MACHINE DIAGRAM This paper uses Papyrus as their tool to design state machine diagram. 2010/9/24 12 CCU CSIE ESL Group Meeting Presentation
E XAMPLE 1: NO ENTRY TRANSITION 2010/9/24 13 CCU CSIE ESL Group Meeting Presentation
E XAMPLE 2: COMPLETION TRANSITION 2010/9/24 14 CCU CSIE ESL Group Meeting Presentation
G ENERATING 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 15 CCU CSIE ESL Group Meeting Presentation
C OMPILING 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 16 CCU CSIE ESL Group Meeting Presentation
O PTIMIZED R ESULTS Required Optimization Code Size(Before) Code Size(After) Optimization Rate Remove unreachable state bytes11393 bytes10.07% Remove transition originated from state that have a completion transition bytes26379 bytes45.90% 2010/9/24 17 CCU CSIE ESL Group Meeting Presentation
R ESULTS INTERPRETATION The semantics lost in code generation, thus large improvement after optimizing from model level in 3 implementations. 2010/9/24 18 CCU CSIE ESL Group Meeting Presentation
O UTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion 2010/9/24 19 CCU CSIE ESL Group Meeting Presentation
B EFORE 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 20 CCU CSIE ESL Group Meeting Presentation
D URING CODE GENERATION The model debugging is unable to debug with removed state. 2010/9/24 21 CCU CSIE ESL Group Meeting Presentation
A FTER CODE GENERATION The UML semantics are visible to the compiler 2010/9/24 22 CCU CSIE ESL Group Meeting Presentation
O UTLINE Introduction Model-based Development For RTES Design Experimental Studies Exploiting UML Semantics For Optimization Conclusion 2010/9/24 23 CCU CSIE ESL Group Meeting Presentation
C ONCLUSION 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 24 CCU CSIE ESL Group Meeting Presentation
T HANK Y OU F OR Y OUR A TTENTION ! 2010/9/24 25 CCU CSIE ESL Group Meeting Presentation
MARTE UML Profile for Modeling and Analysis of Real-Time and Embedded systems /9/24 26 CCU CSIE ESL Group Meeting Presentation
C ODE GENERATION PATTERNS State Pattern State Transition Table _table Nested Switch Case Statements or/niaz_doctor.pdf 2010/9/24 27 CCU CSIE ESL Group Meeting Presentation
RTL AND SSA Register transfer language r_language#RTL_in_GCC Static single assignment signment_form 2010/9/24 28 CCU CSIE ESL Group Meeting Presentation