[llvm-dev] a question about copyPhysReg

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 12 09:50:13 PST 2016


Hi Xiangyang,

> My implementation is wrong actually. Because it cannot differentiate the
> 'move' and 'move-i16'. However, I have no idea to make it work. One thought
> is to define two register classes (one for i16, the other for i32. And they
> share same registers) like the follwing. Then for 'move' instructions and
> copyPhyReg use the different register classes. But this doesn't work either
> because after 'virtual register rewriter' pass, the register class
> information is gone (e.g. we don't know the virtual register R0 belongs to
> GRRegs0 or GRRegs1). In addition, I'm not sure if this (e.g. let one
> register belongs to two register classes) is safe? Any suggestion/hint are
> appreciated. Thanks.

Having registers in two different classes is fine, but as you've seen
you don't always have a register class available. I think LLVM would
model this with sub-registers (so both R0_32 and R0_16 exist, for
example -- I'm sure you could come up with better names). It's easier
if the 16-bit versions are written differently (x86's eax/ax,
AArch64's x0/w0, ...) but that's probably reasonably easy to hack
around in the assembler.

Either that, or you could simply always copy the full 32-bits in
copyPhysReg. I can't see any particular harm in that unless the 16-bit
copy is more efficient or something.

Cheers.

Tim.


More information about the llvm-dev mailing list