Compiler OptimisationThe classical use of program analysis is to facilitate the construction ofcompilers 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 1c±F.Nielson & H.Riis Nielson & C.Hankin (May 2005)2

The structure of a simple compilerlexicalanalysissyntacticanalysisstaticsemanticcheckingcodegeneration-----66666string ofcharactersstring oftokenssymbol table&syntax treesyntaxtreemachinecodeCharacteristics of a simple compiler:•many phases – one or more passes•the compiler is fast – but the code is not very eﬃcientPPA Chapter 1c±F.Nielson & H.Riis Nielson & C.Hankin (May 2005)3

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

The structure of an optimising compilerlexicalanalysissyntacticanalysisstaticsemanticcheckingmachineindependentoptimisationscodegenerationmachinedependentoptimisations-------high-level orintermediate-levelrepresentationlow-levelrepresentationCharacteristics of the optimising compiler:•high-level optimisations: easy to adapt to new architectures•low-level optimisations: less likely to port to new architecturesPPA Chapter 1c±F.Nielson & H.Riis Nielson & C.Hankin (May 2005)4