Docsity

Optimizing Compilers for Portable High Performance: Understanding Compiler Optimization, Study notes of Computer Science

Partial preview of the text

Download Optimizing Compilers for Portable High Performance: Understanding Compiler Optimization and more Study notes Computer Science in PDF only on Docsity!

Optimizing Compilers For Portable High

Performance

Qing Yi

Computer Science, UTSA

Sep 14, 2006

Software development --- productivity and

performance

Architecture Complexity^ Architecture Complexity•Registers•Caches•Networks•Shared Memory•Distributed MemoryCompilers^ Compilers•Register allocation•Locality optimizations•Parallelization

Application ComplexityApplication Complexity •Chemistry•Weather prediction•Physics Simulations•Database managementProgrammers^ Programmers^ •Fortran, C•Java, C#, C++•ZPL, MATLAB, Python

Program Analysis: understanding the

problem before solving it

Computation analysis^ –

Control flow analysis, data-flow analysis, dependence analysis

Memory access analysis^ –

Pointer analysis, array access analysis, aliasing analysis

-^

Reuse analysis, cache conflict analysis

Data storage analysis^ –

Shape analysis, memory layout analysis,

Problem^ –

How well can compilers understand the input program?

-^

How well can compilers understand the machine architecture

Understanding the input programvoid shift (int *a, int n){

int *b = a

for (int i = 0; i < n-1; ++i)

*(a++) = *(b++);

Are a and b aliased?Are elements in a or b aliased?What is the semantics of shift?

Compilers must understand programs at a

higher level

The semantics of compound data structures^ –

Lists, trees, arrays

-^

Relations between individual elements

The semantics of function abstractions^ –

Side-effects, aliasing, modification,

-^

Relations between arguments and result

The semantics of object-oriented abstractions^ –

pure objects

-^

Containers, iterators

-^

Relations between base and derived classes

Compiler optimization: efficient translation of

language constructs

• Eliminating redundancies

–^

Constant propagation, redundant expression elimination,…

• Reorder computations

–^

Instruction scheduling, software pipelining, …

-^

Loop optimizations for better cache locality or betterparallelism

• Resource allocation

–^

Register allocation, data storage optimization

• Enabling transformations

–^

Function inlining, specialization, code refactorization, …

• High-level language optimizations

–^

Virtual function optimization, exception handling,…

Applications that use library abstractions

Applications in library languages^ •

C, C++, Fortran, Java

Applications in scripting languages^ • Matlab, python, perl

Library abstractions --- User-definedabstractions^ • Function abstractions in Fortran, C,• Object-oriented abstractions in C++, Java• Libraries themselves are also applications

Search space of optimizations

•^

Optimizations can be done in many different ways^ –

Which loops to be fused together, which loop nest to block

-^

Which values should reside in registers/caches

-^

How should the array elements be laid out

•^

Safety analysis^ –

Making sure the result is correct

-^

Determined by compilers

•^

Profitability analysis^ –

Making sure the result is beneficial

•^

The search space^ –

Whether to apply an transformation

-^

How to apply a transformation

-^

How to order different transformations

Tuning of optimizations

Dynamic adaptation of behavior^ –

Recursive divide-and-conquer algorithms

Carter, Gustavson, Leiserson et al.

–^

Runtime optimizations

irregular and adaptive applications

– Dynamic compilation

Empirical tuning of optimizations^ ™

Compiler generates many different versions of output ™

The search engine empirically select versions to run andgather performance data ™

The final version is the one with the best performance

Summary: portable compiler optimizations

for high performance

Compiler optimizations need to be aware of^ –

Semantics of user-defined abstractions

-^

Properties of machine architecture

-^

Requirements of dynamic networking environment

Program analysis needs to^ –

Derive high-level semantics from low-level implementation

-^

Precisely model machine behavior

-^

Precisely model program behavior

Empirical tuning of optimizations^ –

Parameterize optimizations with unknown factors

-^

Dynamic profiling of program runtime behavior