ARTICLE: Features of Machine-Dependent Compiler

Translating the programs from the high-level language to the machine language is the most prominent purpose of a compiler. The design of the high-level programming languages is relatively independent of the machine which has been used. The statement implies that in this case, the program syntax analysis process would be relatively independent of the machine. The generation and optimization of the object code are the compiler’s real machine dependencies.

Read the introduction of compilers for high-level language.

The codes are machine dependent in the case of elementary level. It is because of the requirement of the instruction set for the generation of the code of a computer. There are several problems and issues related to this. The allocation of the registers as well as their machine instructions’ rearrangement for the execution of the efficiency improvement process.

Intermediate form

It is the form which is considered for the code optimization technique of the program which has to be compiled. Here, the analysis of the semantics and the syntax of the source statements have already taken place. But there is no performance of the actual translation of the source statements into machine language has not taken place. There are several possible ways of the representation of the analysis and the optimization of the code.

Here, in this section, we use the sequence of quadruples for the representation of the executable instructions. The form of the quadruple is as follows-

Operation op1, op2, result

Here, the function which has to be performed by the object code is the operation. The operands for this operation are op1, op2. The resulting value is placed in the result.

Intermediate code-generation routines create the quadruples which we use in the machine-dependent coding. There are several types of manipulation and analysis process which can be performed for the purpose of the optimization of the code on the quadruples. For instance, there can be a rearrangement of the quadruples for the elimination of the store operations and redundant load. In addition to this, the registers and the temporary variables get the values from the intermediate results. This is done for making the best and the most effective use of the intermediate results. When we are done with the optimization process, then after this there is the translation of the modified quadruples to the machine code.

Order of the quadruples

The order is in the form of the execution of the corresponding object code instructions. Then the analysis of the code is simplified, and it helps in the optimization. One more thing that can be made relatively easy is the translation of the code to the machine instructions.

Machine-Dependent Code Optimization

Here, we will begin with the use of registers and their assignment. There are several general-purpose registers which are used for holding the constants as well as the values of the variables, in addition to the intermediate results.

The registers which can be used for the addressing are present here. But here we will read about on the use of registers as instruction operands.

Which is faster?

The instructions of the machine that use the registers in place of operands take over the speed of the corresponding instructions referring to the memory locations. The preference, in that case, is the use of the registers in all the intermediated results. These are the variables and the results which are to be used in the program later.

Every time memory is fetched, there is the possibility of the assessment of the calculation as an intermediate result to the registers. We can use the value of the memory later as well. It does not make any reference to memory. The other benefit of the memory fetching technique is that it helps in avoiding the unnecessary movement of values between registers and memory. It takes time but does not support the advancement of the computation.

Machine-Independent Compiler Features

Structured Variables

Arrays, records, sets and strings use the structured variables. The allocation of memory to these structured variables is of prime concern here in the context of the generation of code for the reference purpose. Moderate amount of arrays is used here in detail. It can be used in the context of the other types of structured variables.

An example in PASCAL declaration:

A: ARRAY [1….10] OF INTEGER

Here we have ten elements in the array. If each integer in the memory uses one word, then we need to declare the allocation of ten words in the memory for array storage. In the generalized case,

ARRAY [l…. u] OF INTEGER

The allocation of the memory and the number of words can be described here by u-l+1.

We can consider a two-dimensional array.

B: ARRAY [ 0…3, 1...6] OF INTEGER

In the first subscript, there are four different values. They are from 0 to 3. There are six different values in the second transcript. So, the total amount of memory words is 4*6=24 words for storing array.

ARRAY [ l1... u1, l2... u2] OF INTEGER

The number of words which are to be allocated to the array= (u1-l1+1) * (u2-l2+1)

Machine-Independent Code Optimization

Elimination of the common subexpression is the source of the optimization of the source code. There are various points in the program and then computes the same value by the subexpressions. For example, 4*J is common subexpression. There should be code generation by the optimizing compiler for the multiplication of the process to be performed. It takes place only once, but the results are used in both the places.

Detection of the common subexpressions

It happens with the analysis of the program’s intermediate form. One more source of optimization of the code is the removing the loop invariants. These are one of the types of subexpressions different from the rest. It is because they do not change themselves going from one iteration to the next of the loop. That is why we can compute the value of the subexpressions only once and use it multiple times before the loop is entered. It saves the time which goes in the recalculation for each iteration. It is because the time-saving technique can be very significant in the execution of running time of the loops. This is the real sense of optimization. The detection of the loops for the analyzing of the program’s control flow is assumed.