Amrita Bagchi Amrita Bagchi

Code optimization


This is a very serious subject, one that we will not really do justice to in this introductory course. Some optimizations are fairly easy to see.

  1. Since 3 is a constant, the compiler can perform the int to real conversion and replace the first two quads with
  add       temp2 id2  3.0
  
  1. The last two quads can be combined into
  realtoint id1   temp2
  


Code generation


Modern processors have only a limited number of register. Although some processors, such as the x86, can perform operations directly on memory locations, we will for now assume only register operations. Some processors (e.g., the MIPS architecture) use three-address instructions. However, some processors permit only two addresses; the result overwrites one of the sources. With these assumptions, code something like the following would be produced for our example, after first assigning memory locations to id1 and id2.

    LD   R1,  id2
    ADDF R1,  R1, #3.0    // add float
    RTOI R2,  R1          // real to int
    ST   id1, R2
  


Amrita Bagchi

Amrita Bagchi Creator

(No description available)

Suggested Creators

Amrita Bagchi