slides1 - Principles of Program Analysis: A Sampler of...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis . Springer Verlag 2005. c ± Flemming Nielson & Hanne Riis Nielson & Chris Hankin. PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Compiler Optimisation The classical use of program analysis is to facilitate the construction of compilers generating “optimal” code. We begin by outlining the structure of optimising compilers. We then prepare the setting for a worked example where we “optimise” a naive implementation of Algol-like arrays in a C-like language by per- forming a series of analyses and transformations. PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 2
Background image of page 2
The structure of a simple compiler lexical analysis syntactic analysis static semantic checking code generation - - - - - 6 6 6 6 6 string of characters string of tokens symbol table & syntax tree syntax tree machine code Characteristics of a simple compiler: many phases – one or more passes the compiler is fast – but the code is not very efficient PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The structure of an optimising compiler lexical analysis syntactic analysis static semantic checking machine independent optimisations code generation machine dependent optimisations - - - - - - - high-level or intermediate-level representation low-level representation Characteristics of the optimising compiler: high-level optimisations: easy to adapt to new architectures low-level optimisations: less likely to port to new architectures PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 4
Background image of page 4
The structure of the optimisation phase front end program optimiser back end - - - - program analysis transfor- mation - - - ± ± ± ± ± ± ± ± ± ± ± ± ± ± @ @ @ @ @ @ @ @ @ @ @ @ @ @ Avoid redundant computations: reuse available results, move loop in- variant computations out of loops, . .. Avoid superfluous computations: results known not to be needed, results known already at compile time, . .. PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: Array Optimisation program with Algol-like arrays program with C-like arrays optimised program with C-like arrays - - . . . - sequence of analysis and transformation steps PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 6
Background image of page 6
Array representation: Algol vs. C A: array [0:n, 0:m] of integer Base(A) A A A AU 0 1 . . . n 0 1 ··· m 6 j ± i Accessing the (i,j)’th element of A : in Algol: A[i,j] in C: Cont(Base(A) + i * (m+1) + j) PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 7
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
An example program and its naive realisation Algol-like arrays: i := 0; while i <= n do j := 0; while j <= m do A[i,j] := B[i,j] + C[i,j] ; j := j+1 od; i := i+1 od C-like arrays: i := 0; while i <= n do j := 0; while j <= m do temp := Base(A) + i * (m+1) + j ; Cont(temp) := Cont(Base(B) + i * (m+1) + j) + Cont(Base(C) + i * (m+1) + j) ; j := j+1 od; i := i+1 od PPA Chapter 1 c ± F.Nielson & H.Riis Nielson & C.Hankin (May 2005) 8
Background image of page 8
Available Expressions analysis and Common Subexpression Elimination i := 0; while i <= n do j := 0; while j <= m do
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 98

slides1 - Principles of Program Analysis: A Sampler of...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online