What CCAssignToXXXWithShadow means?

Hi, all

  On the website, it says,

CCAssignToRegWithShadow <registerList, shadowList>
  — similar to CCAssignToReg, but with a shadow list of registers

  I don't know when we should use CCAssignToRegWithShadow. Because
I am not a architecture expert, please bear with my naive question.
Take ARMCallingConv.td as an example,

CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>

  If we assign a value to R0(R2), then what happen to R0(R1)?

def RetCC_ARM_AAPCS_Common : CallingConv<[
  CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
  CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
]>;

  Does it mean the samething as above? I searched the web and found
the link below,
  http://www.heyrick.co.uk/assembler/regs.html

It says in some (ARM) processer modes, some register are shadowed.
Does the word "shadow" mean the same thing?

  Thanks!

Regards,
chenwj

Hello

I don't know when we should use CCAssignToRegWithShadow. Because
I am not a architecture expert, please bear with my naive question.
Take ARMCallingConv.td as an example,

ARM is not good example :slight_smile: Look into win64 calling convention. Shadow
means if some register is allocated for incoming argument another one
cannot be used for argument allocation.

On Win64 general purpose registers shadow xmm and vice versa, so, say,
if you put argument into ecx, the xmm0 is marked as already occupied,
if you put argument into xmm1, edx is marked as occupied, etc.

CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0, R1]>>>

If we assign a value to R0(R2), then what happen to R0(R1)?

It will be marked as occupied.

def RetCC_ARM_AAPCS_Common : CallingConv<[
CCIfType<[i32], CCAssignToReg<[R0, R1, R2, R3]>>,
CCIfType<[i64], CCAssignToRegWithShadow<[R0, R2], [R1, R3]>>
]>;

Does it mean the samething as above?

Yes. On ARM shadowing used as a trick to ensure "register alignment"
for i64 arguments - they should always be allocated starting from
even-numbered register and remaining (odd-numbered) one should be left
unallocated.

Hi, Anton

On Win64 general purpose registers shadow xmm and vice versa, so, say,
if you put argument into ecx, the xmm0 is marked as already occupied,
if you put argument into xmm1, edx is marked as occupied, etc.

  I think ecx and xmm0 are physical different registers (not like ecx
and cx), right? So why we cannot use xmm0 while ecx has been used? Is
it just a rule or there are some considerations behind it?

CCIfType<[i32], CCIfAlign<"8", CCAssignToRegWithShadow<[R0, R2], [R0,
R1]>>>

If we assign a value to R0(R2), then what happen to R0(R1)?

It will be marked as occupied.

  If we assign to R0, then R0 is marked occupied. Is it a redundant
statement?

Yes. On ARM shadowing used as a trick to ensure "register alignment"
for i64 arguments - they should always be allocated starting from
even-numbered register and remaining (odd-numbered) one should be left
unallocated.

  If you can point me to some reference aboue "register alignment", I'll
be very appreciate it. Does register alignment bring benefit? In other
word, why register alignment is needed?

  So the word "shadow" on http://www.heyrick.co.uk/assembler/regs.html
means different thing, hugh?

  Thanks! :slight_smile:

Regards,
chenwj

Hello

I think ecx and xmm0 are physical different registers (not like ecx
and cx), right? So why we cannot use xmm0 while ecx has been used? Is
it just a rule or there are some considerations behind it?

Yes. Due to way how varargs stuff is implemented. You always have data
in, say, general-purpose regs regardless of whether it's floating
point or integer.

If we assign to R0, then R0 is marked occupied. Is it a redundant
statement?

Here - yes. Just to make sure alignment works.

If you can point me to some reference aboue "register alignment", I'll
be very appreciate it. Does register alignment bring benefit? In other
word, why register alignment is needed?

This is documented in AAPCS ABI.

So the word "shadow" on http://www.heyrick.co.uk/assembler/regs.html
means different thing, hugh?

Yes. Here "shadow" is Microsoft term.
Check
http://msdn.microsoft.com/en-US/library/zthk2dkh(v=VS.80).aspx
and
http://msdn.microsoft.com/en-US/library/6yy8aw4d(v=VS.80).aspx

for more information