Part 1: Code Movement TransformationCode movement transformation is unification of the common C statements / assembly instructions, which are computed in multiple code paths and moved to a common point. Code movement transformations can be classified under two categories:
Code Sinking TransformationIn Code Sinking Transformation the common C statements / assembly instructions are moved down to a common exit point. Figure 1: C Statement Sinking
In the code shown in Figure 1, the statement "y = a + b" is common in both "if" and "else" block. However the statement will be computed only once since the program control enters either "if" or "else" block. Hence, code sinking transformation will move the statement "y = a + b" to a point below the "else" block. This reduces the number of static evaluations of "y = a + b" (but does not reduce the number of dynamic evaluations of "y = a + b"). Figure 2: Assembly Instruction Sinking
Keil C51 assembly output for 8051 as shown in LHS column of Figure 2 is generated for the C source code snip from open source file ‘Decod.c’ of ITU-T G.723 Speech Coder. Figure 3: Snip from Decod.c
In the code shown in Figure 3, storing of value to 'Ftyp' is a candidate for code sinking transformation at instruction-level. Hence, the assembly instruction for store should be sunk as shown in the RHS column of Figure 2.
|