• No se han encontrado resultados

CAPÍTULO III: VALORACIÓN DE EUGENIO MORENO HEREDIA Y SUS APORTES A

3.1. Valoración de las obras

3.1.2. La temática de la paz

in-struction or sequence of inin-structions where there is a number of possibilities.

Operations making use of registers of the target machine are faster than those using memory operands. Register allocation therefore concerns the utilization of registers in the generated code. The problem can be divided int.o two subproblems, namely register allocation and register assign-ment [Aho86]. Register allocation is a phase of the problem where variables are selected as those that can be advantageously associated with registers, while register assignment concerns the actual association of variables with specific registers. While it is already difficult to find an optimal solution as the problem is NP-complete [Aho86], selection is often hampered by register usage conventions forced by the hardware or operating system. For exam-ple, on the IBM-PC/ AT, for which the Estelle Compiler generates code, only certain registers can be used as index registers and some operations require the operands to be in certain registers while the result is placed in another.

This obviously makes register allocation difficult.

By choosing the order of evaluation of com1fotations, the efficiency of the target code can be effected. Picking a best evaluation order is also an NP-complete problem [Aho86J.

In addition, it is necessary to take the form of the input, as well as the output of the final code generator into account. The output can take three forms namely absolute or relocatable machine language and assem-bly language [Aho86]. Absolute machine language is common for compilers for students of programming, as absolute machine can be placed at a fixed memory address and executed immediately. This is very valuable when small programs need to be repeatedly compiled during debugging. Relocat-able machine language has the advantage of allowing separate compilation of subprograms. However, relocatable machine language programs require linking and loading before execution. The generation of assembly language is very simple, but has the disadvantage that assembly is needed before execution.

Data structures and algorithms for the implementation of code genera-tion can be found in the literature ([Wai74a], [Amm77], [Tre85], [Aho86]).

3.2.2 Code Optimization.

The transformations made on the generated code can never guarantee opti-mal code, and the term "optimization" is therefore a misnomer. "Optimiza-tion" should really be called "improvement".

' , •

~-··

;.;.::.

'"

·' ·.:.;

. -~ "

.·,_ .:

_.·.:·

. :~·: :··: .: ; .. , ,.:~

:.l::·

CHAPTER 3. COMPILERS. 29

There are two types of code-improving transformations, called machine-dependent and machine-inmachine-dependent optimization respectively. The former are transformations that are made to take advantage of a specific machine's features. For example, special purpose instructions such as an instruction to increment the contents of a register or a storage location should be used where possible. In addition, a register can be used as a storage location where a variable is frequently accessed.

Machine-independent optimizations are transformations which improve the generated code without taking the features of the target machine into consideration. The concept of a basic block is important for distinguishing between local and global optimizations. A basic block is a sequence of con-secutive statements in which flow of control enters the at the beginning and leaves at the end without halt or possibility of branching except at the end [Aho86]. Local optimizations are those optimizations which can be applied by examining instructions within a basic block, while other optimizations are called global. ·

Examples of local optimizations are those which can be classified as func-tion preserving transformafunc-tions such as common subexpression elimi-nation, copy propagation, dead- code elimielimi-nation, constant folding

[Aho86] and constant propagation [Tre85], and loop optimizations such as code motion, induction-variable elimination, unswitching, strength reduction [Aho86], and loop unrolling [Tre85].

Common subexpressions (also known as redundant subexpressions [Tre85J) are subexpressions which occur more than once in a program and need only be evaluated once. For example, in the expression

(A+ B)

*

(C

+

D) +(A+ B)

*

E

the addition "A

+

B" need only be performed once. It can be argued that programmers are taught to program in a non- redundant manner, thus ques-tioning the value of this transformation. However, array addressing often provides redundant subexpressions over which the programmer has no con-trol, and programming redundantly often improves readability, a common requirement of a program. For example,

A[i,j] := A[i,j]

+

B[i,j]

is an instance of array addressing where the address "A[i,j]" need only be evaluated once, and if the array variable "A" and "B" have the same dimensions, the subexpression for the offset need only be evaluated once.

CHAPTER 3. COMPILERS. 30 Copy propagation is concerned with the use of

"t"

wherever possible for every occurrence of "A" after a statement "A := B

+

C", where "t" is the result of the expression "B

+

C". This transformation often causes dead-code to be formed, which can then be removed. Variable folding is used in the same way where the assignment "A:= B" occurs for "B", a variable.

Dead code is code that has no purpose. For example, a statement which conditionally prints debug information if a boolean variable is true, can be removed if the variable is obviously false at that stage. Say the statements

debug := false;

if debug then S;

occur m a program. Then from copy propagation the second statement would become

if false then S;

which can be removed as "S" will never be executed.

Constant folding is used where expressions can be replaced by their val-ues at compile time. For example, the assignment

A:= 1+2 + 3;

can be replaced by the assignment A:= 6;

Subexpressions can also be reduced via constant folding. For example, the expression

1+2+A+3+4+B+5+6 can be reduced to the expression

3+A+7+B+ll

Constant propagation is similar to copy propagation as the values re-sulting from constant folding are replaced in all possible occurrences of the variable in an assignment with a value produced by constant folding.

Code motion (also known as frequency reduction) is used in loop optimization.where code known as the invariant is removed from the loop and performed before the loop. Thus, in cases where the code inside the loop is executed more than once the code is vastly improved, for the case

CHAPTER 3. COMPILERS. 31

Documento similar