Higher-Order and Symbolic Computation, , 1–20 (1999) c 1999 Kluwer Academic Publishers, Boston. Manufactured in The Netherlands. Combining Program and Data Specialization {sandrine.chirokoff,charles.consel,renaud.marlet}@irisa.fr Compose project, IRISA / INRIA - Université de Rennes 1, Campus Universitaire de Beaulieu, 35042 Rennes cedex, France, http://www.irisa.fr/compose Abstract. Program and data specialization have always been studied separately, although they are both aimed at processing early computations. Program specialization encodes the result of early computations into a new program; while data specialization encodes the result of early computations into data structures. In this paper, we present an extension of the Tempo specializer, which performs both program and data specialization. We show how these two strategies can be integrated in a single specializer. This new kind of specializer provides the programmer with complementary strategies which widen the scope of specialization. We illustrate the benefits and limitations of these strategies and their combination on a variety of programs. Keywords: program transformation, partial evaluation, program specialization, data specialization, combining program and data specialization 1. Introduction Program and data specialization both aim at performing computations which depend on values that are available early. However, they differ in the way the result of early com- putations are encoded: on the one hand, program specialization encodes these results in a residual program, and on the other hand, data specialization encodes these results in data structures. More precisely, program specialization performs a computation when it only relies on early data, and inserts the textual representation of its result in the residual program when it is useful to calculate the final result with the late values. In essence, it is because a new program is being constructed that early computations can be encoded in it. Furthermore, because a new program is being constructed it can be pruned, that is, the residual program only corresponds to the control flow that could not be resolved given the available data. As a consequence, program specialization optimizes the control flow since fewer control decisions need to be taken by the specialized program. However, because it requires a new program to be constructed, program specialization can lead to code explosion if the size of the specialization values is large. For example, this situation can occur when a loop needs to be unrolled and the number of iterations is high. Not only does code explosion cause code size problems, but it also degrades the execution time of the specialized program dramatically because of instruction cache misses. The dual notion to specializing programs is specializing data. Data specialization splits the execution of a program into two phases. The first phase, called the loader, performs the early computations and stores their results in a data structure called a cache. Instead of generating a specialized program which contains the textual representation of values, data specialization generates a program to perform the second phase: it only consists of