[LLVMdev] The live interval of write-only registers

Chris Lattner sabre at nondot.org
Mon Dec 12 20:26:26 PST 2005


On Tue, 13 Dec 2005, Tzu-Chien Chiu wrote:

> In my ISA, some registers are write-only. These registers serve as
> output ports, writing to these registers will output the values to an
> external device. They cannot be read. So their live intervals should
> not be joined with any other registers.

Ok.  Since they are not really registers in the sense that LLVM is used 
to, I wouldn't suggest even exposing them as registers.  You may as well 
just tell LLVM they are immediates or something, and have the asm printer 
print them however you like.  As an example, the X86 has I/O ports which 
can be read and written to.  These are not thought of as registers, but 
they have the same property.  They are accessed with in/out instructions, 
not with "register writes".

> The only way I know to do this is defining several instruction
> 'templates' for an opcode (of course automatically generated by a
> script) similar to the x86 code generator in LLVM:
>
> InstrInfo.td:
> // ORC: output register class
> // TRC: temp register class
>
> def ADDoaa : Inst<0x1234, (ops ORC:$dest, TRC:$src0, $TRC:src1), "add
> $dest, $src0, $src1)
>
> The letters (oaa) postfixed to the opcode (ADD) is the template. In
> this way the output register won't be joined because they are of
> different register classes.

Yes.  Following the same approach, defining the output registers as 
immediates would also work, and would guarantee that the register 
allocator wouldn't try to spill their values or do anything else nasty.

> However, the problem with the method is that there are too many
> register classes in the ISA.
>
> for destinations:
> o: outptu register
> x: a relatively addressed output register
> i: integer register
> f: floating-point temporary register
>
> for sources:
> a: floating-point temporary register
> r: a relatively addressed temporary register
> c: a constant register holding an immediate values
>
> I do not list all class, but imagine how many combinations there are
> for a three-address operations like MAD (multiply-and-add). It's very
> very inconvenient in the code generator to manipulate the opcodes
> because TableGen generates an 'opcode' for each of the templates of an
> operation.

Yes, this is a lot.  :(

> For example, this a code snippet for the file generated by the TableGen tool:
...
> Somewhere in my code, I have to write:
>  unsigned opcode = MI->getOpcode(); // MachineInstr*
>  if (CMPfaaaa == opcode ||
>      CMPfaaar == opcode ||
>      CMPfaara == opcode ||
>      ...

Where do you have to write this code?

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/




More information about the llvm-dev mailing list