Determining Register Class of an Operand

If I have two physical registers, A and B, how do I know whether I may
replace A with B in a machine instruction? My concern is that A may be
in a restricted register class of which B is not a member. An example
is trying to replace the x86 CL register in a shift operation.

It seems like the only way to get a register class for a physical
register is via TargetRegisterInfo::getMinimalPhysRegClass but that is
far too conservative in general.

Is there any way, given an instruction and a register operand, to find
out which exact register class models the semantics/restrictions of that
operand position in the instruction?

                           -David

Hi David,

If I have two physical registers, A and B, how do I know whether I may
replace A with B in a machine instruction

It sounds like TargetInstrInfo::getRegClass is the function you want.
The result has a "contains" method as you'd expect.

Cheers.

Tim.

Tim Northover <t.p.northover@gmail.com> writes:

Hi David,

If I have two physical registers, A and B, how do I know whether I may
replace A with B in a machine instruction

It sounds like TargetInstrInfo::getRegClass is the function you want.
The result has a "contains" method as you'd expect.

Ah, perfect! Thanks!

                                 -David