1 / 26

AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS

AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS. Vineeth Kumar Paleri. Regional Engineering College, calicut Kerala, India. (Currently, Visiting Assistant Professor, Dept. Computer and Information Science, IUPUI). Code Optimization ( Transformation ): Introduction.

brandy
Télécharger la présentation

AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS Vineeth Kumar Paleri Regional Engineering College, calicut Kerala, India. (Currently, Visiting Assistant Professor, Dept. Computer and Information Science, IUPUI).

  2. Code Optimization ( Transformation ): Introduction • To reduce the space or running of the code. • Scalar and Parallel Transformations • Scalar Transformations: Reduce the number of instructions executed. Eg. Useless code elimination, Constant propagation. • Parallel Transformations: Maximize parallelism and Memory locality Eg. Loop Interchange, Loop fusion.

  3. Code Transformation: Stages • Data flow analysis Collects information regarding ‘definitions’ and ‘uses’ of variables. • Modification of code • An example: constant propagation X:= 5; Z:X+Y

  4. Automatic Generation of code Optimizers: • Formal specification of code transformations. • Framework for the specification. • Design of a specification language. • Development of a generator to produce code from specifications.

  5. Framework for Specification of code Transformations: • Dependence Relation • Control dependence • Data dependence • Flow dependence • Anti dependence • Output dependence

  6. Control Dependence: Si : if( x = c) Sj : y :=1 Sj is control dependent on Si; Si c Sj

  7. Data Dependence: • Flow dependence Si : x := a + b Sj : y := x + c Sj is flow dependent on Si; Si Sj • Anti dependence Si : x := y + a Sj : y := a + b Sj is anti dependent on Si; Si Sj _

  8. Output dependence Si : z := x + a Sj : z := y + b Sj is Output dependent on Si; Sio Sj

  9. Intermediate Representation • High-level intermediate representation • Abstract syntax trees • Low-level intermediate representation • Three – address code • d s t : = scr1 op scr2

  10. Specification Format • Precondition • Combination of some basic conditions • Basic conditions • Conditions to identify interested program elements • (E.g.. Statements and loops) • Checks for dependence relations between pairs of statements • Action • Sequence of primitive actions to perform the transformation • Primitive actions • delete-stmt(Si) • insert-stmt(Si,position) • replace-operand(opr1,opr2)

  11. Formal Specification:An Example Useless code elimination Si: definition-stmt(Si) : (∄Sj : Sj  Si : Si  Sj) {delete-stmt(Si);}

  12. Specification Language • Syntax transformation-name: [ action-quantifier : conditional-expropt : conditional-expropt {action-list} ] • An Example:Useless code elimination useless-code-elimination: [ foreach stmt-i: : useless-stmt(stmt-i) { delete-stmt(stmt-i); } ]

  13. Specification Language :Features • Powerful enough to express almost all traditional scalar transformations • Permits modularity in expressing complex specifications • Permits extensions to the language

  14. Automatic Generation of Code Optimizers

  15. Stanford University Intermediate Format - SUIF • SUIF consists of • A Kernel • Defines the intermediate representation • Provides functions to access and manipulate the • intermediate representation. • A toolkit • C and Fortran front-ends • MIPS back-end • A set of compiler passes • Each pass typically performs a single analysis or • transformation and then writes the results on to the file

  16. Optimizer Generator • Input : Specification for code transformations in the • specification language • Output : C language code performing those transformations • Lexical analysis • Using LEX • Syntax analysis • Using YACC • C language code generation • By syntax-directed translation approach

  17. Optimized Generator Syntax-directed translation approach • Semantic actions are associated with productions of the grammar • to emit code • Precondition part is used to generate code • For identifying the program elements of interest • To check the conditions to be satisfied for the transformation • Action part is used to generate code • To perform the corresponding transformations

  18. Optimizer Generator : Syntax-directed Translation Approach Transformation-name : [ foreach program-element{semantic actions to generate a loop construct for iteration over the instances of the program} : conditional-expr1 {semantic actions to generate code for checking the conditions to select the program elements of interest} : conditional-expr2 {semantic actions to generate code to check the conditions that have to be satisfied for the transformation} : action-list {semantic actions to generate code for performing the corresponding transformations}

  19. Optimizer Generator : An Example • Useless code elimination • Specification useless-code-elimination : [ foreach stmt-i : : useless-stmt (stmt-i) {delete-stmt(stmt-i);}

  20. Generated code outline Void useless-code-elimination (…..) { …… while ( ! end-of-instruction-list ) { …… stmt-i = next-instruction ; if ( useless-stmt (stmt-i)) {delete-stmt (stmt-i);} } }

  21. Dependence Analysis • Computation of Control Dependence • Algorithm • begin • Construct the control flow graph, CFG; • Construct the augment control flow graph, ACFG; • Construct the reverse augmented control flow graph, RACFG; • Compute the dominators of each node in RACFG; • Compute the dominance frontier of each node in RACFG; • Compute control dependencies,from the dominance frontier information; • end

  22. Dependence Analysis Computation of Data Dependence • Iterative data-flow analysis • Data dependence computation are formulated as data-flow analysis problems by setting up corresponding data-flow equations

  23. Dependence Analysis : Computation of Data Dependence • Example : Flow Dependence Computation • Flow dependence computation is essentially the identification of all • reachable uses of each definition in a program, with the following • data-flow equations: • in [B] = gen [B] U ( out [B] – kill [B] ) • out [B] = US ε succ (B) in [S] • Where, • in [B] is the set of uses reachable from the beginning of basic block B, • out [B], the set of uses reachable from the end of B, • gen [B], the set of upward exposed uses in B, and • kill [B], the set of uses reachable from the end of B, of all variables • defined in B

  24. The Transformation System : Experiments • Generated optimizers were applied on LINPACK benchmark routines • Correctness of the generated optimizers verified by comparing the output of the optimized code with the output from the original unoptimized code

  25. Conclusion • Generated code for all traditional scalar transformations from formal specifications • Verified correctness of the generated code • System can be extended to include parallel transformations • Limitations • Could not specify some of the transformations in the chosen • framework • The transformation system is not efficient

  26. Reference Vineeth Paleri . An environment for automatic generation of code optimizers . PhD Thesis , Department of Computer science and Automation , Indian Institute of Science , Bangalore, 1999. Also, (Technical Report : TR No. IISC-CSA-2001-2 , http://www.csa.iisc.ernet.in )

More Related