09-opt

09-opt - Optimizing compilers Compiler structure token...

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

View Full Document Right Arrow Icon
Optimizing compilers Copyright c ± 2007 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for proFt or commercial advantage and that copies bear this notice and full citation on the Frst page. To copy otherwise, to republish, to post on servers, or to redistribute to lists, requires prior speciFc permission and/or fee. Request permission to publish from hosking@cs.purdue.edu. CS502 Register allocation 1 Compiler structure (eg, canonical trees/tuples) (eg, canonical trees/tuples) Intermediate code generator generator Machine code low ! level IR low ! level IR (eg, type checking) Semantic analysis token stream machine code syntax tree syntax tree Parser Optimizer Potential optimizations: Source-language ( AST ): constant bounds in loops/arrays loop unrolling suppressing run-time checks enable later optimisations IR : local and global CSE elimination live variable analysis code hoisting enable later optimisations Code-generation (machine code): register allocation instruction scheduling peephole optimization CS502 Register allocation 2 Optimization Goal : produce fast code What is optimality? Problems are often hard Many are intractable or even undecideable Many are NP -complete Which optimizations should be used? Many optimizations overlap or interact CS502 Register allocation 3 Optimization DeFnition: An optimization is a transformation that is expected to: improve the running time of a program or decrease its space requirements The point: “improved” code, not “optimal” code sometimes produces worse code range of speedup might be from 1.000001 to 4 ( or more ) CS502 Register allocation 4
Background image of page 1

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

View Full DocumentRight Arrow Icon
Machine-independent transformations applicable across broad range of machines remove redundant computations move evaluation to a less frequently executed place specialize some general-purpose code Fnd useless code and remove it expose opportunities for other optimizations CS502 Register allocation 5 Machine-dependent transformations capitalize on machine-speciFc properties improve mapping from IR onto machine replace a costly operation with a cheaper one hide latency replace sequence of instructions with more powerful one (use “exotic” instructions) CS502 Register allocation 6 A classical distinction The distinction is not always clear: replace multiply with shift s and add s CS502 Register allocation 7 Optimization Desirable properties of an optimizing compiler code at least as good as an assembler programmer stable, robust performance ( predictability ) architectural strengths fully exploited architectural weaknesses fully hidden broad, efFcient support for language features instantaneous compiles Unfortunately, modern compilers often drop the ball CS502 Register allocation 8
Background image of page 2
Optimization Good compilers are crafted, not assembled
Background image of page 3

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

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

Page1 / 10

09-opt - Optimizing compilers Compiler structure token...

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

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