Automatic Mode Inference for Logic Programs

In general, logic programs are undirected, i.e., there is no concept of “input” and “output” arguments to a procedure. An argument may be used either as an input or as an output argument, and programs may be executed either in a “forward” direction or in a “backward” direction. However, it is often the case that in a given program, a predicate is used with some of its arguments used consistently as input arguments and others as output arguments. Such mode information can be used by a compiler to effect various optimizations. This paper considers the problem of automatically inferring the models of the predicates in a program. The dataflow analysis we use is more powerful than approaches relying on syntactic characteristics of programs. Our work differs from that of Mellish in that (1) we give a sound and efficient treatment of variable aliasing in mode inference; (2) by propagating instantiation information using state transformations rather than through dependencies between variables, we achieve greater precision in the treatment of unification, e.g. through =/2; and (3) we describe an efficient implementation based on the dynamic generation of customized mode interpreters. Several optimizations to improve the performance of the mode inference algorithm are described, as are various program optimizations based on mode information.

[1]  Saumya K. Debray,et al.  Detection and Optimization of Functional Computations in Prolog , 1986, ICLP.

[2]  Heikki Mannila,et al.  Flow Analysis of Prolog Programs , 1987, SLP.

[3]  Bart Demoen,et al.  Improving the Execution Speed of Compiled Prolog with Modes, Clause Selection, and Determinism , 1987, TAPSOFT, Vol.2.

[4]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[5]  Maurice Bruynooghe,et al.  The memory management of PROLOG implementations , 1980 .

[6]  Saumya K. Debray,et al.  Efficient dataflow analysis of logic programs , 1988, JACM.

[7]  Uday S. Reddy,et al.  Transformation of Logic Programs into Functional Programs , 1984, SLP.

[8]  Maurice Bruynooghe Adding Redundancy to Obtain more Reliable and Readable Prolog Programs , 1982, ICLP.

[9]  Bart Demoen,et al.  Abstract Interpretation: Towards the Global Optimization of Prolog Programs , 1987, SLP.

[10]  Doug DeGroot,et al.  AND-Parallelism of Logic Programs Based on a Static Data Dependency Analysis , 1985, COMPCON.

[11]  Saumya K. Debray Flow Analysis of a Simple Class of Dynamic Logic Programs , 1987, SLP.

[12]  Gert Smolka Making control and data flow in logic programs explicit , 1984, LFP '84.

[13]  Lee Naish,et al.  Negation and Control in Prolog , 1986, Lecture Notes in Computer Science.

[14]  Saumya K. Debray,et al.  Functional computations in logic programs , 1989, TOPL.

[15]  Suzanne W. Dietrich,et al.  Extension Tables: Memo Relations in Logic Programming , 1987, SLP.

[16]  Chris Mellish,et al.  Some Global Optimizations for a Prolog Compiler , 1985, J. Log. Program..