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

Slides:



Advertisements
Similar presentations
SSA and CPS CS153: Compilers Greg Morrisett. Monadic Form vs CFGs Consider CFG available exp. analysis: statement gen's kill's x:=v 1 p v 2 x:=v 1 p v.
Advertisements

Data-Flow Analysis II CS 671 March 13, CS 671 – Spring Data-Flow Analysis Gather conservative, approximate information about what a program.
Lecture 11: Code Optimization CS 540 George Mason University.
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Control Flow Analysis (Chapter 7) Mooly Sagiv (with Contributions by Hanne Riis Nielson)
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Program Representations. Representing programs Goals.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
Lecture 01 - Introduction Eran Yahav 1. 2 Who? Eran Yahav Taub 734 Tel: Monday 13:30-14:30
Common Sub-expression Elim Want to compute when an expression is available in a var Domain:
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Cpeg421-08S/final-review1 Course Review Tom St. John.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Chair of Software Engineering Fundamentals of Program Analysis Dr. Manuel Oriol.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
CS 412/413 Spring 2007Introduction to Compilers1 Lecture 29: Control Flow Analysis 9 Apr 07 CS412/413 Introduction to Compilers Tim Teitelbaum.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Compiler Construction
Recap from last time: live variables x := 5 y := x + 2 x := x + 1 y := x y...
Machine-Independent Optimizations Ⅰ CS308 Compiler Theory1.
Direction of analysis Although constraints are not directional, flow functions are All flow functions we have seen so far are in the forward direction.
McGill University Proposal Exam School of Computer Science Ph.D. Candidate in the Modelling, Simulation and Design Lab Eugene Syriani.
Precision Going back to constant prop, in what cases would we lose precision?
Invitation to Computer Science 5th Edition
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
Software (Program) Analysis. Automated Static Analysis Static analyzers are software tools for source text processing They parse the program text and.
Optimization software for apeNEXT Max Lukyanov,  apeNEXT : a VLIW architecture  Optimization basics  Software optimizer for apeNEXT  Current.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
10/1/2015© Hal Perkins & UW CSEG-1 CSE P 501 – Compilers Intermediate Representations Hal Perkins Autumn 2009.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Department of Computer Science A Static Program Analyzer to increase software reuse Ramakrishnan Venkitaraman and Gopal Gupta.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Review Joey Paquet,
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Dataflow Analysis Topic today Data flow analysis: Section 3 of Representation and Analysis Paper (Section 3) NOTE we finished through slide 30 on Friday.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
May 31, May 31, 2016May 31, 2016May 31, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University Azusa Pacific University,
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
CS412/413 Introduction to Compilers Radu Rugina Lecture 18: Control Flow Graphs 29 Feb 02.
Control Flow Analysis Compiler Baojian Hua
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
CSC 4181 Compiler Construction
1 HPJAVA I.K.UJJWAL 07M11A1217 Dept. of Information Technology B.S.I.T.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
1 Compiler Construction Vana Doufexi office CS dept.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Compiler Design (40-414) Main Text Book:
Chapter 1 Introduction.
Simone Campanoni Dependences Simone Campanoni
Chapter 1 Introduction.
Compiler Lecture 1 CS510.
Compiler Construction
Data Flow Analysis Compiler Design
Chapter 10: Compilers and Language Translation
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, Also, (Technical Report : TR No. IISC-CSA , )