3. OPTIMIZATION OF BASIC BLOCKS
There are two types of basic block optimizations.
They are :
Structure -Preserving Transformations
.1 Structure- Preserving Transformations:
The primary Structure-Preserving Transformation on basic blocks are: � Common sub-expression elimination
3.2 Common sub-expression elimination:
Common sub expressions need not be computed over and over again. Instead they can be computed once and kept in store from where it’s referenced when encountered again – of course providing the variable values in the expression still remain constant.
The 2nd and 4th statements compute the same expression: b+c and a-d
Basic block can be transformed to
3.3 Dead code elimination:
It’s possible that a large amount of dead (useless) code may exist in the program. This might be especially caused when introducing variables and procedures as part of construction or error -correction of a program – once declared and defined, one forgets to remove them in case they serve no purpose. Eliminating these will definitely optimize the code. 3.4 Renaming of temporary variables:
3.5 Interchange of two independent adjacent statements:
can be interchanged or reordered in its computation in the basic block when value of t1 does not affect the value of t2.
3.6 Algebraic Transformations:
a :=b+c e :=c+d+b
the following intermediate code may be generated:
a :=b+c t :=c+d