Automatic mode inference for logic programs

Saumya K. Debray, David S. Warren

Research output: Contribution to journalArticlepeer-review

88 Scopus citations


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.

Original languageEnglish (US)
Pages (from-to)207-229
Number of pages23
JournalThe Journal of Logic Programming
Issue number3
StatePublished - Sep 1988

ASJC Scopus subject areas

  • Logic


Dive into the research topics of 'Automatic mode inference for logic programs'. Together they form a unique fingerprint.

Cite this