On 2010-08-25, at 3:27 PM, chevalma@iro.umontreal.ca wrote:
I was thinking of only having pointer + offset, where both of these are SSA temporaries, and so the offset can either be a constant or a variable.
When you say "pointer" do you mean "object reference"? It would be better to use that term, or simply "reference" to denote a boxed value (a tagged pointer which the GC can handle, move around, etc). To me a "pointer" is simply the address of something in memory, with no concept of garbage collection.
The point is really to allow our object pointers to remain unchanged and safe for the GC to collect/modify while still allowing us to read and write in the middle of an object.
Optimizations that are specific to x86, such as those involving having the load/store instructions doing the actual pointer/offset arithmetic, should probably be done in the backend. LLVM seems to do it that way.
If your "abstract machine" only has a "load reference+constant_offset" and "load reference+register_offset" then you will have to implement a "load reference+register_offset+constant_offset" using 2 abstract instructions (add and load). A peephole optimization might be able to combine these 2 instructions into a single x86 instruction, but the register allocator will have reserved a *real* temporary register for the addition and even though it will go unused it will have caused additional register pressure. It is simpler to have all the cases:
load reference + constant_offset load reference + constant_offset + register_offset load reference + constant_offset + register_offset * constant_multiplier
in the "abstract machine", and for the back-end to expand these into more than one machine instruction if the target machine does not implement the abstract instruction directly. It will be necessary however for the back-end to communicate to the previous pass (register allocator) how many temporary registers it will need (i.e. for "load reference + constant_offset + register_offset * constant_multiplier" on x86 there is 0 temporary registers needed and on MIPS (and many others) there is 1 needed).
Marc