The University of Arizona
banner image

  Automatic Mode Inference for Logic Programs

Saumya Debray and David S. Warren
Department of Computer Science
SUNY at Stony Brook
Stony Brook, NY 11794, U.S.A.
 

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 modes 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 (i) we give a sound and efficient treatment of variable aliasing in mode inference; (ii) 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 (iii) 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.