# AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS Vineeth Kumar Paleri Regional Engineering College, calicut Kerala, India. (Currently,

## Presentation on theme: "AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS Vineeth Kumar Paleri Regional Engineering College, calicut Kerala, India. (Currently,"— Presentation transcript:

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  To reduce the space or running of the code.  Scalar and Parallel Transformations  Scalar Transformations: Reduce the number of instructions executed. Reduce the number of instructions executed. Eg. Useless code elimination, Constant propagation. Eg. Useless code elimination, Constant propagation.  Parallel Transformations: Maximize parallelism and Memory locality Maximize parallelism and Memory locality Eg. Loop Interchange, Loop fusion. Eg. Loop Interchange, Loop fusion.

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

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

Framework for Specification of code Transformations :  Dependence Relation  Control dependence  Data dependence  Flow dependence  Anti dependence  Output dependence

Control Dependence : S i : if ( x = c) S i : if ( x = c) S j : y :=1 S j is control dependent on S i ; S i  c S j

Data Dependence :  Flow dependence S i : x := a + b S j : y := x + c S j is flow dependent on S i ; S i  S j S j is flow dependent on S i ; S i  S j  Anti dependence S i : x := y + a S j : y := a + b S j is anti dependent on S i ; S i  S j _

 Output dependence S i : z := x + a S j : z := y + b S j is Output dependent on S i ; S i  o S j

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

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(S i ) insert-stmt(S i,position) replace-operand(opr1,opr2)

Formal Specification:An Example Useless code elimination  Si: definition-stmt(S i ) : ( ∄ S j : S j  S i : S i  S j ) {delete-stmt(S i );}

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

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

Automatic Generation of Code Optimizers

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

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

Optimized Generator 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 Syntax-directed translation approach

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-expr 1 { semantic actions to generate code for checking the conditions to select the program elements of interest } : conditional-expr 2 { 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}

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

  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);} }

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

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

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] = U S ε 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

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

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

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 ) http://www.csa.iisc.ernet.in

Download ppt "AUTOMATIC GENERATION OF CODE OPTIMIZERS FROM FORMAL SPECIFICATIONS Vineeth Kumar Paleri Regional Engineering College, calicut Kerala, India. (Currently,"

Similar presentations