11.3 THE MACHINE MODEL


11.2 PROBLEMS THAT HINDER GOOD CODE GENERATION

There are three main difficulties that we face when attempting to generate efficient object code, namely:

  1. Selection of the most-efficient instructions to represent the computation specified by the three-address statement;

  2. Deciding on a computation order that leads to the generation of the more-efficient object code; and

  3. Deciding which registers to use.

Selecting the Most-Efficient Instructions to Represent the Computation Specified by the Three-Address Statement

Many machines allow certain computations to be done in more than one way. For example, if a machine permits an instruction AOS for incrementing the contents of a storage location directly, then for a three-address statement a = a + 1, it is possible to generate the instruction AOS a, rather than a sequence of instructions like the following:

 MOVE a, R  ADD #1, R  MOVE R, a 

Now, deciding which instruction sequence is better is the problem. This decision requires an extensive knowledge about the context in which these three-address statements will appear.

Deciding on the Computation Order that Will Lead to the Generation of More-Efficient Object Code

Some computation orders require fewer registers to hold intermediate results than others. Now, deciding the best order is very difficult. For example, consider the basic block:

If the order of computation used is the one given in the basic block t 1- t 2- t 3- t 4, then the number of registers required for holding the intermediate result is more than when the order t 2- t 3- t 1- t 4 is used.

Deciding on Registers

Deciding which register should handle the computation is another problem that stands in the way of good code generation. The problem is further complicated when a machine requires register-pairs for some operands and results.




Algorithms for Compiler Design
Algorithms for Compiler Design (Electrical and Computer Engineering Series)
ISBN: 1584501006
EAN: 2147483647
Year: 2005
Pages: 108
Authors: O G Kakde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net