[LLVMdev] Instructions on a target with no general purpose registers

David Given dg at cowlark.com
Sat Jul 5 14:09:37 PDT 2014


On 7/5/14, 3:59 PM, Edwin Amsler wrote:
[...]
> So, my question is, when I'm defining my ins, outs and registers for these instructions, is it going to be a problem that different instructions outputs are defined by the function that is called? And I guess, how do I tell LLVM it can't pick any old register for a given instruction?

You can define a register class which matches a single register only and
then define an instruction which accepts parameters of only that class.
Unfortunately I actually tried this for my Videocore code generator and
the most likely outcome is that the register allocator will turn up its
toes and die. It really doesn't like this.

However, if you squint hard enough the 6502 becomes a processor with 256
byte-sized registers --- zero page. You may have better luck with a
processor model which uses a subset of these as your registers, and
possibly not telling LLVM about A, X and Y at all. Plus that gets you
useful free stuff like indirect indexed, which you can use to implement
*(addr+offset) for 8-bit offsets, and sneak a 16-bit add for free out of
the processor.

...

In another life I help look ater the ACK compiler suite, which is
ancient and crufty and produces terrible code, but dates from about the
era when the 6502 was still a thing and I've played with its 6502 code
generator (and the 8080 code generator); these processors will basically
not run modern languages acceptably. It's because modern languages are
all stack-frame based, and these processors don't have any support for
stack relative accesses.

On the Z80 you can just about fake it by using ix or iy as a user stack
pointer, but it's painfully slow, painfully bloaty (8 bytes of code to
read or write a 16-bit value from the stack frame!) and basically just
painful. I believe later Z80s eventually gained a stack-relative load
instruction, but I don't know if there was a corresponding store.

The 6502 isn't quite as bad. If your user stack pointer is in zero page,
you can use indirect indexed to give access to a 256-byte stack frame,
but it's not pretty:

  ldy #offset
  lda (sp), y    # load high(?) byte
  iny
  ldx (sp), y    # load low byte

...seven bytes, I think.

At least it's not as bad as the 8080.

Being able to forbid recursion and therefore map every stack frame
statically into RAM would improve things no end, as now every stack slot
has a compile-time known address; I remember asking here about this ages
back and was told that there wasn't a built-in pass to do this, but it
would be fairly easy to do. *shrug*

Or you could just start using FORTRAN.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "Feminism encourages women to leave their husbands, kill their
│ children, practice withcraft, destroy capitalism and become lesbians."
│ --- Rev. Pat Robertson

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 876 bytes
Desc: OpenPGP digital signature
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140705/89a5d5a4/attachment.sig>


More information about the llvm-dev mailing list