Automatic mode inference for logic programs,☆☆

https://doi.org/10.1016/0743-1066(88)90010-6Get rights and content
Under an Elsevier user license
open archive

Abstract

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.

Cited by (0)

This work was supported in part by the National Science Foundation under grant number DCR-8407688.

☆☆

This is a revised version of a paper presented at the Third Symposium on Logic Programming, Salt Lake City, Utah, Sept. 1986.