> I am currently working (as a hobbyist, err non university level
> student) on a project which compares trusted C optimization methods
> over global boundaries. Basically, I'm trying to construct a C
> compiler which provides a documentation of steps it makes to generate
> optimized C code. I am in a bit of a hurry, and am beginning to think
> that it would be a waste of my time to write an x86 backend for my
> compiler when I could use a C-- compiler.
We would be thrilled for you to add some optimizations to our C--
compiler.
> One of the important factors of the project is to be able to show
> differences between the code before and after it was optimized. I
> fear a code generator which makes major optimizations (although I'm
> fine with peephole optimizations, as any code generator I would
> write would include one) may somewhat invalidate or skew my
> results.
We share your fear. Quick C-- uses the 'transactional' system
developed by David Whalley and used by David's vpoiso tool.
The key to this idea is that even a major optimization can be broken
up into small 'transactions', each of which preserves semantics.
The general picture goes like this:
1. You add new code in bits and pieces, usually one instruction at a
time. Each new instruction preserves semantics (becuase its
result is not used) and is one transaction.
2. When all your new code is in place, you start modifying existing
code to use the results of the new code. With luck you can
change one instruction at a time, but sometimes you may have to
perform a substitution in multiple instructions as a single
transaction. Example: a whole bunch of instructions decide to
use EBX instead of ECX.
3. Finally you usually wind up with some dead code, which is swept
away (again one instruction at a time) by our existing dead-code
pass.
We have the equivalent of vpoiso built into Quick C--, and provided
you use the transaction mechanism properly, it is excellent at
identifying the exact place where your optimizer has introduced a
fault, *provided* you have a good test suite.
What we lack that vpo has is the tool Ann Bailey built called 'VET',
which takes a logged stream of transactions and allows you to
visualize the optimization offline, play the transactions backwards
and forwards, and so on. That tool is actually a fair amount of work
to write...
> I would like to use Quick C-- to generate machine code for x86
> platforms (and maybe others?) but am wondering if anyone thinks
> this would be safe with respect to my output. Is there any way to
> minimize or turn off major optimizations?
Yes, at present Quick C-- has a highly configurable 'optimization
backplane', which is essentially a domain-specific language for
configuring the optimizer.
> Does Quick C-- not make optimizations which will affect the output
> on a major level?
At present, Quick C-- makes very few optimizations. The critical ones
are coalescing of register-register moves (done in the register
allocator), peephole optimization, and dead-code elimination.
We would dearly love to have some forms of redundancy elimination, but
at present we don't.
> At the current state (medium development) I'm working
> with a fairly ad hoc intermediate language which consists of a flow
> graph and expression trees (I'm an AST fan, and like to make
> optimizations with those rather than things like SSA or TAC). The
> later stage will probably convert the intermediate code into a simple
> representative form and then to C--.
We have a nice, functional control-flow graph with expression trees.
There was a paper in the 2005 ML Workshop. I think you will like the
data structure. I have made a few refinements in Haskell for the
Glasgow Haskell compiler and I hope eventually there will be a journal
submission.
Norman
_______________________________________________
Cminusminus mailing list
[email protected]
https://cminusminus.org/mailman/listinfo/cminusminus