| Previous | Table of Contents | Next |
The hardware does not directly execute the MI instructions. They are either first translated to the hardware instruction set before the program can be executed, or a separate component in SLIC interprets certain of the MI instructions one at a time. An example of the interpreted MI instructions is the Advanced 36 APIs. We call the step that converts the MI instructions to the lower level hardware instructions a translation rather than a compilation because it performs only a part of the compile function. Earlier, the target of this translation was the IMPI instruction set; now it is the PowerPC instruction set.
The MI instruction set is not an HLL in the usual sense. It is more accurate to look at MI as the intermediate representation in a modern HLL compiler. Some like to describe the MI instruction set as being similar to an HLL that needs to be translated to a lower level or executed interpretively. A short description of optimizing compilers will illustrate why thinking of MI as an intermediate representation is a better view.
Figure 4.1 shows the structure of a modern, optimizing compiler. A compiler typically consists of two or more passes, or phases. (A pass is simply one phase in which the compiler reads and transforms the entire program. The term phase is often used interchangeably with pass.)
Figure 4.1 Structure of an Optimizing Compiler
A pass in a compiler transforms a high-level, more abstract representation of the program into a lower-level representation. Eventually, this process reaches the hardware instruction set. This optimizing compiler structure was first created in the 1960s to manage the complexities of the many transformations needed to create optimized code. A single-pass compiler is limited in what it can do to optimize the generated code. Simply put, a single-pass compiler cannot look ahead in the instruction stream to see what is going to happen next. A multipass compiler can look ahead and prepare for upcoming computations. Assigning variables to registers based on their interaction with other variables, storing cache contents that are no longer needed, and prefetching operands are but a few of the optimizations that a multipass compiler can accomplish.
Compiler optimizations can greatly increase the performance of a program, especially if the program is run on a processor that can run multiple instructions in parallel. A RISC processor has this kind of parallelism and requires an optimizing compiler to achieve high performance. Using multiple passes also makes compiler writing easier.
The first phase of the compiler shown in Figure 4.1 is often called the front end of the compiler. The job of the front end is to take the HLL instructions and transform them into a common intermediate form. The back end of the compiler consists of the optimization phases and the code generation phase. Front ends are language dependent, while back ends are hardware dependent.
If the common intermediate form is independent of both the language and the hardware, then it can be used in several compilers. Each new language needs only a new front end. Similarly , once a back end has been written for a specific hardware implementation, all front ends will work. This mix-and-match approach makes it easier to put new languages on a computer.
The MI instruction set is similar to the common intermediate form used in a compiler. An HLL compiler generates the MI form of the program. A translator below the MI takes this form, performs the optimizations, and generates the IMPI or PowerPC instructions. The translator is very similar to the back end of a compiler.
The common intermediate form of some languages is designed to be either translated or interpreted. In Chapter 11 we look at Java, which has such an intermediate form. Called byte code, this intermediate form of Java has also been included in the MI.
The MI instruction set is not always a replacement for the common intermediate form in all AS/400 compilers. Some AS/400 language compilers have their own intermediate form; others do not. The following description of the internals of the AS/400 language compilers illustrates how the MI fits into the overall compiler operations.
| Previous | Table of Contents | Next |