[comp.lang.c] Source-to-source transformation/optimization in C.

oz@yunexus.UUCP (Ozan Yigit) (08/20/89)

Does anyone know of any attempts to do source-to-source transformation
for the purposes of code simplification/optimization on C ?? I would
prefer references for academic work, source code, etc. Some of the
readership may also feel that there are issues worthy of discussion
under this title, so be it. I am more interested in real work than
speculation, and will summarize any e-mail replies I get (if any).
[Yes, I know the complications due to cpp, comments etc. No need to
tell me that it is hard to do. I do not intend to do it. I am just
interested in what (if anything) is done in the area.]

oz
-- 
The king: If there's no meaning	   	    Usenet:    oz@nexus.yorku.ca
in it, that saves a world of trouble        ......!uunet!utai!yunexus!oz
you know, as we needn't try to find any.    Bitnet: oz@[yulibra|yuyetti]
Lewis Carroll (Alice in Worderland)         Phonet: +1 416 736-5257x3976

gnb@melba.bby.oz (Gregory N. Bond) (08/25/89)

In article <3276@yunexus.UUCP> oz@yunexus.UUCP (Ozan Yigit) writes:
>Does anyone know of any attempts to do source-to-source transformation
>for the purposes of code simplification/optimization on C ?? 

James Gosling, he of emacs fame and now at Sun working on NeWS,
presented a paper at the Australian Unix systems Users Group
conference (AUUG 89) last month, titled "Ace: a syntax-driven C
preprocessor".  I include the abstract:

	"This document presents the ace preprocessor for C programs.  Unlike
	cpp, which operates on characters, ace operates on syntax trees. The
	user specifies syntax trees which are used as templates against which
	program fragments are matched.  Positive matches cause trees to be
	rewritten.  Ace can be used as a special-purpose optimizer and can be
	controlled by the programmer."

The driving force behind this was to make graphics blatting routines
partameterizable, so the actual loop need only be written once.  The
ace macros then expand the code for each combination of pixel depth,
line orientation, edge clipping, raster ops etc.  Constant cases in
if() & while() are recognised and rewritten.  Boolean tests are
simplified.  Reduntant code is deleted.  The result is a function
expanded from 1 page to 20 pages, which is infinitly easier to
maintain, but has all the performance advantages of the explicit case.

Ace also has a tradeoff operator that will select one of two code
sequences depending on estimated time and code size, and user
specified levels of optimizing (e.g. space unless it's 30% faster).
There are facilities for telling ace how likely an expression is to be
true (for branch prediction) and how many times a loop will be run to
make these decisions more accurate.

In all, a facinating program, and VERY useful in these and similar
circumstances.  Gosling was fairly emphatic that the program was
internal and not a releaseable product.  Pity.

Unfortunately I know of no other publication (there are no
references), and the conference proceedings (AUUGN, Vol 10, no 4)
probably aren't available in the US.  You might try contacting Gosling
direct at Sun for a copy of the paper.

Greg.
-- 
Gregory Bond, Burdett Buckeridge & Young Ltd, Melbourne, Australia
Internet: gnb@melba.bby.oz.au    non-MX: gnb%melba.bby.oz@uunet.uu.net
Uucp: {uunet,pyramid,ubc-cs,ukc,mcvax,prlb2,nttlab...}!munnari!melba.bby.oz!gnb