Presentation is loading. Please wait.

Presentation is loading. Please wait.

U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John.

Similar presentations


Presentation on theme: "U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John."— Presentation transcript:

1 U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John Cavazos University of Delaware

2 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 2 Compiler Overview Lexical analyzer Syntax analyzer Semantic analyzer Code optimizer Code generator Source program Target program Error handlerSymbol-table

3 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 3 Compiler Frontend Lexical Analyzer Parser Semantic Analyzer Source Program Token Stream Syntax Tree Intermediate Rep Gen IR Series of passes Source program – Written in a HLL Lexical analysis – Convert keywords into “tokens” Parser – Forms a syntax “tree” (statements, expressions, etc.) Semantic analysis – Type checking, etc. We will not cover the front end in this class! (See CISC 672)

4 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 4 Compiler Middleend and Backend Code Optimizer Code Generator IR Target program This is where the “interesting” stuff happens … enough to fill an entire grad-level course Code optimization – “improves” the intermediate code  Consists of machine independent & dependent opts Code generation – register allocation, instruction scheduling

5 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 5 Traditional Optimizations Analyze the program  Where is this value used?  Is this value recomputed? Reduce the total number of operations  Common subexpression elimination  Strength reduction Maintain values in registers  Elimination of redundant loads

6 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 6 Developing an Optimization FormulateImplementEvaluate Refine Formulate the problem based on:  Intuition  Extract properties from a program Implement the algorithm Evaluate results based on test programs Use results to refine the algorithm

7 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 7 Building an Optimizing Compiler Strict requirements Must be correct for all possible inputs Must provide robust solution  Small changes in input should not produce wild changes in output Good optimizing compilers are crafted Careful selection of transformations Careful use of algorithms and data structures

8 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 8 Building an Optimizing Compiler Compilers are engineered objects Try to minimize running time of compiled code Try to minimize compile time Try to limit use of compile-time space Try to keep engineering efforts reasonable With all these constraints, results are … unexpected!

9 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 9 Quick Look at Real Compilers Consider inline substitution Replace procedure call with body of called procedure  Rename to handle naming issues  Widely used (and important!) for optimizing OOPs

10 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 10 Characteristics of Function Inlining Safety: almost always safe Profitability: avoid overhead of a procedure call Opportunity: inline leaf procedures How well do compilers handle inlined code?

11 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 11 5 Real Good Compilers Source Program Compiler InlinerCompiler Execute & time Experimental Setup Execute & time

12 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 12 The Study Cooper/Hall/Torczon (Software-Practice & Experience 91) Eight programs, five compilers, five processors Eliminated over 99% of dynamic calls in 5 of programs Measured speed of original versus transformed code Expected uniform speed up, at least from call overhead What really happened?

13 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 13 Change in Execution Time

14 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 14 Happens with Good Compilers! Input code violated assumptions made by compiler writers  Longer procedures  More names  Different code shapes Exacerbated problems that are hard to detect!  Imprecise analysis  Algorithms that scale poorly  Tradeoffs between global and local speed  Limitations in the implementations The compiler writers were surprised (most of them)

15 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 15 JikesRVM Translation From Bytecode to HIR Optimization of HIR HIR Jikes Front End Translation From HIR to LIR Optimization of LIR Translation From LIR To MIR Optimization of MIR Final Assembly Jikes Back End LIR MIR Optimized HIR Optimized LIR Optimized MIR Binary Code

16 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 16 Levels of IR HIR (High Level IR) LIR (Low Level IR) MIR (Machine Specific IR)

17 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 17 HIR Operators similar to Java bytecode Example: ARRAYLENGTH, NEW, GETFIELD, BOUNDS_CHECK, NULL_CHECK Symbolic registers instead of an implicit stack Contains separate operators to implement explicit checks for run-time exceptions (eg., array-bounds checks)

18 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 18 LIR Details of JikesRVM runtime and object layout Example: GET_TIB (vtable), INT_LOAD (for getfield) Expands complicated HIR structures such as TABLE_SWITCH

19 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 19 MIR Similar to assembly code Details of target architecture are introduced Register Allocation is performed on MIR

20 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 20 A Tour of the JikesRVM codebase

21 U NIVERSITY OF D ELAWARE Computer & Information Sciences Department 21 Next Time Read the following Wikipedia pages (section) Graph Theory (Basics) Basic Blocks Control Flow Graphs


Download ppt "U NIVERSITY OF D ELAWARE C OMPUTER & I NFORMATION S CIENCES D EPARTMENT Optimizing Compilers CISC 673 Spring 2009 Overview of Compilers and JikesRVM John."

Similar presentations


Ads by Google