






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!























Michael O’Boyle
March, 2011 Iterative Compilation
1
Overview
Dynamic Compilation
Specialisation –
DyC
Calpa
Dynamic Binary translation –
Dynamo
Iterative Compilation
3
Background
Delaying compiler operations until runtime has been used for many years
Interpreters translates and execute at runtime
Languages developed in the 60s eg Algol 68 allowed dynamic memory allocationrelying on language specific runtime system to mange memory
Lisp more fundamentally has runtime type checking of objects
Smalltalk in the 80s deferred compilation to runtime to reduce the amount ofcompilation otherwise required in the 00 setting
Java uses dynamic class loading to allow easy upgrading of software
Iterative Compilation
4
Runtime specialisation
For many, runtime optimisation is “adaptive optimisation”
Although wide range of techniques, all are based around runtime specialisation.Constant propagation is a simple example.
Specialisation is a technique that has been used in compiler technology formany years especially in more theoretical work
Specialising an interpreter with respect to a program gives a compiler
Can we specialise at runtime to gain benefit with minimal overhead? Staticallyinserted selection code vs parameterised code vs runtime generation.
Iterative Compilation
6
DyC
One of the best known dynamic program specialisation techniques based ondynamic code generation.
The user annotates the program defining where there may be opportunities forruntime specialisation.
Marks variables and memory locations that are
static
within a particular scope.
The system generates code that checks the annotated values at runtime andregenerates code on the fly.
By using annotation,
the system avoids over-checking and hence runtime
overhead. This is at the cost of additional user overhead.
Iterative Compilation
March, 2011
7
DyC
Focuses on static runtime values and memory locations.
Static binding-time
analysis to identify static runtime expressions.
Polyvariant division and specialisation to replicate control-flow path and divideinto static and run-time variable sub-graphs.
A specialised compiler is inserted at dynamic sub-graphs.
At runtime it
compiles code with values and stores this in a cache for later use and thenexecutes it.
Later invocations look up the code and use it.
Uses full unrolling, strength
reduction,
zero/copy
propagation,
dead-assignment
elimination
and
static
loads.
Iterative Compilation
March, 2011
9
DyC Example
make_static(CMTRIX,CROWS,CCOLS,CROW,CCOL);
-- USER annotation
for(irow=0; irow<irows; ++irow){
rowbase = irow-CROWSO2;for(icol= 0; icol<icols;++icol){
colbase = icol-CCOLSO2; sum =0.0;for (CROW=0; CROW<CROWS; ++CROW){
-- unroll loop
for (CCOL=0; CCOL <CCOLS; +CCOL){
-- unroll loop
weight = cmatrix @[CROW]@[CCOL];
-- constant load
x = image[rowbase+CROW][colbase+CCOL];weighted_x = x * weight;sum = sum + weighted_x;
outbuf[irow][icol] = sum;
M. O’Boyle
Iterative Compilation
10
DyC Example
Matrix cmatrix has the following structure :
When CROW and CCOL loop is unrolled, the static loads from cmatrix will beinlined
Allows elimination of redundant computation
M. O’Boyle
Iterative Compilation
12
DyC Example
for(irow=0; irow<irows; ++irow){
rowbase = irow- 1;for(icol= 0; icol<icols2;++icol){
colbase = icol-1;
x = image[rowbase][colbase+1];-- It 1:crow=0,ccol=1sum = x;x = image[rowbase+1][colbase];-- It 3:crow=1;ccol=0sum = sum + x;
outbuf[irow][icol] = sum;
M. O’Boyle
Iterative Compilation
13
DyC Example
Asymptotic speedup and a range programs varies from 1.05 to 4.
Strongly depends on percentage of time spent in the dynamically compiledregion. Varies from 9.9 to 100 %
Low overhead from 13 cycles to 823 cycles per instruction generated
Break-even point low.
However
relies
on
user
intervention
which
may
not
be
realistic
in
large
applications
Relies on user
correctly
annotating the code
Iterative Compilation
March, 2011
15
Calpa for DyC
Calpa is a frontend to DyCIt usesinstrumentationto guideannotationinsertion
compiledC programdynamiccompiler
C program
instrumentedC program
annotatedC program
DyC compiler
Calpa instrumenter
Calpa Annotation
valueprofile
sampleinput
Iterative Compilation
16
Calpa for DyC
i=
L1: if i >= size goto L
uelem = u[i]velem = v[i]t = uelem * velemsum = sum + ti = i + 1goto L
∅ i, sizei, u
i, v
i, u
, v
i, sum, u
, v
i ∅
At each statement calculate cadidate static variables.
Over larger region determine candidate division - all possible sub sets. Searchfor the best set based on value profile data using gradient search.
Iterative Compilation
18
Dynamic Binary Translation
The key idea is to take one ISA binary and translate it into another ISA binaryat runtime.
In fact this happens inside Intel processors where x86 is unpacked and translatedinto an internal RISC opcode which is then scheduled. The TransMeta Crusoeprocessor does the same. Same with IBM legacy ISAs.
Why don’t we do this statically? Many reasons!
The source ISA is legacy but the processor internal ISA changes.
It is
impossible to determine statically what is the program. It is not legal to storea translation. It can be applied to a local ISA for long term optimisation
Iterative Compilation
March, 2011
19
Focuses on binary to binary optimisations on the same ISA. One of the claimsis that it allows compilation with -01 but overtime provides -03 performance.
Catches dynamic cross module optimisation opportunities missed by a staticcompiler. Code layout optimisation allowing improved scheduling due to biggersegments.
Branch alignment and partial procedural inlining form part of the
optimisations
Aimed as way of improving performance from a shipped binary overtime.
Has to use existing hardware - no additional fragment cache available
Iterative Compilation