ITERATIONSPACES IN COMPILER DESIGN
BY
S.SUBHALAKSHMI
M.SC(CS)
NADAR SARASWATHI COLLEGE OF ARTSANDSCIENCE
Content:
Iteration
Constructing Iteration Spaces From Loop Nests
Execution Order For Loop Nests
Matrix Formulation Of Inequalities
Incorporation Symbolic Constants
Controlling The Order Of Execution
Changing Axes
ITERATION:
Iteration is the repetition of a process in order to
generate a sequence of outcomes.
The sequence will approach some end point or end
value.
Each repetition of the process is a single iteration, and
the outcome of each iteration is then the starting point of the next
iteration.
CONSTRUCTING ITERATION SPACES FROM LOOP NESTS:
The sort of loop nests that can be handled by the
techniques to be developed.
Each loop has a single loop index, which we can assume
is incremented by 1 at each iteration.
That assumption is without loss of generality, since if the
Incrementation is by integer c>1.
We can always replace uses of index i by uses of ci+a for
some positive or negative constant a, and then increment i by 1 in the
loop.
The bounds of the loop should be written as affine
expressions of outer loop indices.
EXECUTION ORDER FOR LOOP NESTS:
A sequential execution of a loop nest sweeps through
iterations in its iteration space in an ascending lexicographic order.
A vector i=[i0,i1,…..in] is lexicographically less than
another vector i’=[i’0,i’1,…….,i’n’], written i<i’, if and only if there
exists an m<min(n,n’) such that [i0,i1,…..im]=[i’0,i’1,……,i’m] and
im+1<i’m+1.
Note that m=0 is possible ,and in fact common.
MATRIX FORMULATION OF INEQUALITIES:
The iterations in a d-deep loop can be represented
mathematically as
{i in Zd|Bi+b >0}
Here,
1.Z, as is conventional in mathematics, represents the set of
integers-positive, negative, and zero.
2.B is a d*d integer matrix,
3.b is an integer vector of length d,
4.0 is a vector of d 0’s.
INCORPORATING SYMBOLIC CONSTANTS:
Sometimes we need to optimize a loop nest that involves
certain variables that are loop- invariant for all the loops in the nest.
We call such variables symbolic constants, but to describe
the boundaries of an iteration space.
We need to treat them as variables and create an entry for
them in the vector of loop indexes.
CONTROLLING THE ORDER OF EXECUTION:
The linear inequalities extracted from the lower and upper
bounds of a loop body define a set of iterations over a convex
polyhedron.
The representation assumes no execution ordering between
iterations within the iteration space.
The original program imposes one sequential order on the
iterations, which is the lexicographic order with respect to the loop
index variables ordered from the outermost to the innermost.
However, the iterations in the space can be executed in any
order as long as their data dependences are honored.
The problem of how we choose an ordering that honors the
data independences and optimizes for data locality and parallelism is
hard and is dealt with later starting.
PROJECTION:
The loop bounds of the outer loop index in a two-deep loop
nest by projecting the convex polyhedron representing the iteration
space onto the outer dimension of the space.
The projection of a polyhedron on a lower-dimensional
space is intuitively the shadow cast by the object onto that space.
LOOP-BOUNDS GENERATIONS:
We have defined Fourier-Motzkin elimination, the
algorithm to generate the loop bounds to iterate over a convex
polyhedron is straight forward.
We compute the loop bounds in order, from the innermost
to the outerloops.
All the inequalities involving the innermost loop index
variables are written as the variable’s lower or upper bounds.
We then project away the dimension representing the
innermost loop obtain a polyhedron with one fewer dimension.
We repeat until the bounds for all the loop index variables
are found.
CHANGING AXES:
Sweeping the iteration space horizontally and
vertically.
They are just two of the most common ways of
visiting the iteration space.
There are many other possibilities we can sweep
the iteration spaces.
Complier Design

Complier Design

  • 1.
    ITERATIONSPACES IN COMPILERDESIGN BY S.SUBHALAKSHMI M.SC(CS) NADAR SARASWATHI COLLEGE OF ARTSANDSCIENCE
  • 2.
    Content: Iteration Constructing Iteration SpacesFrom Loop Nests Execution Order For Loop Nests Matrix Formulation Of Inequalities Incorporation Symbolic Constants Controlling The Order Of Execution Changing Axes
  • 3.
    ITERATION: Iteration is therepetition of a process in order to generate a sequence of outcomes. The sequence will approach some end point or end value. Each repetition of the process is a single iteration, and the outcome of each iteration is then the starting point of the next iteration.
  • 4.
    CONSTRUCTING ITERATION SPACESFROM LOOP NESTS: The sort of loop nests that can be handled by the techniques to be developed. Each loop has a single loop index, which we can assume is incremented by 1 at each iteration. That assumption is without loss of generality, since if the Incrementation is by integer c>1.
  • 5.
    We can alwaysreplace uses of index i by uses of ci+a for some positive or negative constant a, and then increment i by 1 in the loop. The bounds of the loop should be written as affine expressions of outer loop indices.
  • 7.
    EXECUTION ORDER FORLOOP NESTS: A sequential execution of a loop nest sweeps through iterations in its iteration space in an ascending lexicographic order. A vector i=[i0,i1,…..in] is lexicographically less than another vector i’=[i’0,i’1,…….,i’n’], written i<i’, if and only if there exists an m<min(n,n’) such that [i0,i1,…..im]=[i’0,i’1,……,i’m] and im+1<i’m+1. Note that m=0 is possible ,and in fact common.
  • 8.
    MATRIX FORMULATION OFINEQUALITIES: The iterations in a d-deep loop can be represented mathematically as {i in Zd|Bi+b >0} Here,
  • 9.
    1.Z, as isconventional in mathematics, represents the set of integers-positive, negative, and zero. 2.B is a d*d integer matrix, 3.b is an integer vector of length d, 4.0 is a vector of d 0’s.
  • 10.
    INCORPORATING SYMBOLIC CONSTANTS: Sometimeswe need to optimize a loop nest that involves certain variables that are loop- invariant for all the loops in the nest. We call such variables symbolic constants, but to describe the boundaries of an iteration space. We need to treat them as variables and create an entry for them in the vector of loop indexes.
  • 11.
    CONTROLLING THE ORDEROF EXECUTION: The linear inequalities extracted from the lower and upper bounds of a loop body define a set of iterations over a convex polyhedron. The representation assumes no execution ordering between iterations within the iteration space. The original program imposes one sequential order on the iterations, which is the lexicographic order with respect to the loop
  • 12.
    index variables orderedfrom the outermost to the innermost. However, the iterations in the space can be executed in any order as long as their data dependences are honored. The problem of how we choose an ordering that honors the data independences and optimizes for data locality and parallelism is hard and is dealt with later starting.
  • 13.
    PROJECTION: The loop boundsof the outer loop index in a two-deep loop nest by projecting the convex polyhedron representing the iteration space onto the outer dimension of the space. The projection of a polyhedron on a lower-dimensional space is intuitively the shadow cast by the object onto that space.
  • 14.
    LOOP-BOUNDS GENERATIONS: We havedefined Fourier-Motzkin elimination, the algorithm to generate the loop bounds to iterate over a convex polyhedron is straight forward. We compute the loop bounds in order, from the innermost to the outerloops.
  • 15.
    All the inequalitiesinvolving the innermost loop index variables are written as the variable’s lower or upper bounds. We then project away the dimension representing the innermost loop obtain a polyhedron with one fewer dimension. We repeat until the bounds for all the loop index variables are found.
  • 16.
    CHANGING AXES: Sweeping theiteration space horizontally and vertically. They are just two of the most common ways of visiting the iteration space. There are many other possibilities we can sweep the iteration spaces.