Register assignment in tree-structured programs
نویسنده
چکیده
Much complex decision-making is performed routinely by the software of a computer system. It is appropriate to study more thoroughly the performance of this built-in decisionmaking, because it can strongly influence the efficiency of the entire system. One objective of compilers is to produce a reasonably efficient machine-language version of a user’s program. Traditionally, one of the best opportunities for improving the compiler-produced machinelanguage program has been in devising efficient policies for assigning quantities to the computer’s registers. The programs of interest here involve flow of control which can be represented by a tree structure. The problem of assigning index registers in such programs is formulated as a (nonserial) disc-Prolog problem. Following the resulting recursion equations leads to a pohcy which the compiler could follow to minimize costs. The policy decisions specify those steps in the program where particular quantities should be loaded or stored into registers. An example involving a brancbing program is solved by this method. A host of resource allocation problems are found in the operation of computer systems. Much of the decision-making in such environments is automated as part of the system software. Operating systems, for example, regularly manage the resources of the computer-conse~g memory, exploiting parallelism wherever possible, and scheduling the processors for high utilization. Compilers, as well, contain a wealth of decision-making apparatus which is routinely exercised as part of the process of translating user programs into machine language. Because of the high usage of such software, the quality of this built-in decision-making can strongly influence the efficiency of the entire system. Underlying the present study is the belief that some of the complex decision-making that is automated in computer software can benefit from more thorough analysis. This observation is certainly not new. Perhaps the OElsevia North Holland, Inc., 1979 0020-0255/79/040g3-12gOl.75 84 WILLIAM W. AGRESTI most outstanding example is the application of queueing theory in computer operating systems. The software of interest here is the compiler or language processor. An important objective in compiling is to consider the efficiency of the machine-language program that is generated. As a user’s program in, say, FORTRAN is being translated, decisions are made regarding the sequence of machine-language instructions which should be produced to correspond to each FORTRAN statement. During this compiling process, transformations are applied which change parts of the program into equivalent versions which will execute faster or consume less memory. It is suggested that this process of successive transformation of the program is a staged decision process whose behavior might be clarified by a dynamic-programming formulation. The availability of these so-called “program optimizations” is extremely important-especially to the construction of large application and systems programs which will be run on a regular basis. Their presence in compilers makes it feasible for programmers to use high-level languages and still get a relatively efficient program without having to resort to assembly language. Structured programming, which puts a premium on clarity and organization, can sometimes lead to inefficient programs. With the program optimizations automated, structured programmin g can be safely pursued and its benefits realized. From the earliest compilers until the present, register assignment has offered one of the best opportunities for program optimization. The general problem is to describe rules by which a compiler can make the beat possible use of a computer’s available registers. When several program statements are scanned, the compiier can note what values are required in each of the calculations. This pattern of usage suggests a plan for keeping certain values in high-speed registers over a span of several statements. In this way, the program will run faster because the required quantities will not have to be fetched from memory. Of course, the number of registers is limited; so the problem becomes one of devising a schedule for loading these values into registers-ideally, a schedule which permits the fastest possible execution of the program. The problem has been widely studied in several versions, depending on such factors as the range of the allocation (over a few statements or an entire program), the existence of common subexpressions, and practical considerations of implementation on a particular machine. Registers which are used for indexing are the special concern here. Indexing is a valuable programming technique for operating on data which are arranged in storage in some systematic way, It can help reduce the running time of the machine-language programs produced by compilers. The problem of assigning index registers has been studied by Worwitz et al. [ 1] and Kennedy [2]. In [l], a procedure was given for specifying which quantities should occupy index registers at each point in a program so that the number of memory references REGISTER ASSIGNMENT IN TREE-STRUCTURED PROGRAMS 85 Fig. 1. Examples of tree structures. (from U)AD and STORE operations) is minimized. The programs in [l] involved only a straight-line sequence of statements, i.e., no branches or loops. More recent work in [2] improved the procedure and suggested extensions to programs containing simple loops. The major departure here is to consider programs which possess nonlinear flow of control-the branches which are found in real computer programs. In FORTRAN terms, we can now include some programs which contain conditional and branching statements like IF and GO TO. The programs we study are those whose flow of control can be represented as a tree structure. Figure 1 gives some examples. To solve the index register allocation problem in such programs, a new methodology, dynamic programming, is introduced. 1. THE INDEX-REGISTER ASSIGNMENT PROBLEM We are interested in those computers which provide some number of registers which can be used for indexing. Two types of instructions are of interest. One type simply refers to the contents of an index register. For example, ADD 1 ,K(2) would mean that two quantities are to be added together. One operand is in register 1. The second operand is in memory at the address given by K plus the contents of index register 2. The second type of instruction modifies the contents of the index register. For example, if we added one to the contents of index register 2, then the instruction would be of the second type. Where there are more indices than registers, the problem is to specify what indices should occupy index registers at each step in the program. Because our only concern is with the references to indices in a program, we use “program” to mean a sequence of such references. Where the index has been modified, an asterisk is placed next to it. A program, assuming one reference per step, might look like the following: 86 WILLIAM W, AGRESTI This program tells us that index x1 is referenced at step 1, index x3 is referenced and modified at step 2, and so on. If we denote by P(i) the index referenced at the ith step, then P(1) = xi, P(2) 3 x3*, . . . , P(8)= x2. We assume that the machine has NR index registers, and we define a register configuration Qi to be an unordered set of NR indices which occupy the index registers at step i in the program. An allocation A for a n-step program P is a sequence of configurations,
منابع مشابه
Optimal Register Allocation in Polynomial Time
A graph-coloring register allocator that optimally allocates registers for structured programs in polynomial time is presented. It can handle register aliasing. The assignment of registers is optimal with respect to spill and rematerialization costs, register preferences and coalescing. The register allocator is not restricted to programs in SSA form or chordal interference graphs. It requires ...
متن کاملStructured Programs have Small Tree-Width and Good Register Allocation (Extended Abstract)
The register allocation problem for an imperative program is often modelled as the coloring problem of the interference graph of the control-ow graph of the program. The interference graph of a ow graph G is the intersection graph of some connected subgraphs of G. These connected subgraphs represent the lives, or life times, of variables, so the coloring problem models that two variables with o...
متن کاملAll Structured Programs have Small Tree-Width and Good Register Allocation
The register allocation problem for an imperative program is often modelled as the coloring problem of the interference graph of the control-ow graph of the program. The interference graph of a ow graph G is the intersection graph of some connected subgraphs of G. These connected subgraphs represent the lives, or life times, of variables, so the coloring problem models that two variables with o...
متن کاملThe complexity of register allocation
In compilers, register allocation is one of the most important stages with respect to optimization for typical goals, such as code size, code speed, or energy efficiency. Graph theoretically, optimal register allocation is the problem of finding a maximum weight r-colorable induced subgraph in the conflict graph of a given program. The parameter r is the number of registers. Large classes of pr...
متن کاملThe Treewidth of Java Programs
Intuitively, the treewidth of a graph G measures how close G is to being a tree. The lower the treewidth, the faster we can solve various optimization problems on G, by dynamic programming along the tree structure. In the paper M.Thorup, All Structured Programs have Small Tree-Width and Good Register Allocation [8] it is shown that the control-flow graph of any goto-free C program is at most 6....
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید
ثبت ناماگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید
ورودعنوان ژورنال:
- Inf. Sci.
دوره 18 شماره
صفحات -
تاریخ انتشار 1979