UPPSALA THESES IN COMPUTING SCIENCE 26 Compilation Techniques for Prolog

Lindgren, T. 1996: Compilation Techniques for Prolog, Uppsala Theses in Computing Science 26. 36pp. Uppsala. ISSN 0283-359X, ISBN 91-506-1181-X. Current Prolog compilers are largely limited to optimizing a single predicate at a time. We propose two methods to express the global control of Prolog programs. The rst method transforms a Prolog program into a continuation-passing style, where all operations have explicit success and failure continuations. The second method directly constructs a control ow graph from the Prolog program. This is done by rst performing an analysis that determines the potential targets of success or failure for every predicate, then by using this information to build the control ow graph. We develop an optimization, factoring, that reduces the size of the analysis solution substantially. Uninitialized output variables are an important feature of all high-performance implementations of logic programming language today. We show that a polyvariant output variable analysis is more precise and robust than the previously proposed monovariant analyses, while remaining fast and practical. Garbage collection is a potential bottleneck in a high-performance Prolog implementation. We show that generational copying garbage collection can be adapted to Prolog, and that such a collector is considerably faster than currently used Prolog garbage collectors. A number of problems speci c to Prolog and its implementation techniques are presented and solutions provided. Finally, we propose Reform Prolog, a recursion-parallel dialect of Prolog. We show that recursion-parallelism can be e ciently exploited on today's shared memory multiprocessors by means of a restricted execution model, a streamlined runtime system and sophisticated compilation techniques. Our experiments indicate that Reform Prolog runs programs with low parallelization overheads (compared to standard sequential Prolog implementations), yet attains high speedups even on large multiprocessors. Thomas Lindgren, Computing Science Department, Uppsala University, Box 311, S-751 05 Uppsala, Sweden. c Thomas Lindgren 1996. ISSN 0283-359X ISBN 91-506-1181-X Printed by Graphic Systems AB, Stockholm 1996. Acknowledgments First of all, thanks to H akan Millroth, my advisor. His guidance and mentoring have been invaluable. Johan Bevemyr has been a close friend and colleague ever since our undergraduate days. Without his hard work on Reform Prolog and his knack for low-level implementation, things would have been much harder, not to mention less fun. Per Mildner has been a great help and a conscientous critic of my later work. I have been fortunate in having ready access to his experience. Thanks to my external examiner, Peter Van Roy, and to my readers, Jonas Barklund, Mats Carlsson, Seif Haridi and Sven-Olof Nystrom. I appreciate your e orts. The computing science department has provided a stimulating setting for research. In particular, Patric Hedlin, who helped with hacking Reform Prolog; Magnus Nordin, who provided perspectives on static analysis, computer graphics and animation and many other things; and Mattias Waldau, who deserves a big thanks for early inspiration. I have been fortunate in discussing the ideas of this thesis with many of the premier people in logic programming. In particular, I would like to thank Saumya Debray, Ulrich Neumerkel, Paul Tarau and David H.D. Warren for discussions over the years. John Lloyd and Tony Bowers were helpful and hospitable during a visit at Bristol; Malcolm Brown kindly helped me and Johan at the Edinburgh Parallel Computing Centre. Thanks to all of you. Finally, many thanks to my friends and family for making these years enjoyable.