[Question] The TargetRegisterClass has a confusing method.

The method below takes in a register and returns a register. To me this makes no sense because
when I already have a register, why would I need to get it? Could someone please explain the
transformation that is happening here?

/// getRegister - Return the specified register in the class.
///
unsigned getRegister(unsigned i) const {
assert(i < getNumRegs() && “Register number out of range!”);
return RegsBegin[i];
}

The "i" in here isn't the register but an index into the RegsBegin array.

-bw

Aye, I understand it’s an index into an array, but what is the difference between the index i and the return value.

Do I have to worry that register values from a TargetRegisterClass could be either zero based or some other base? Are there other methods that rely on zero based in the TargetRegisterClass?

I thought register values were “global,” but this transformation makes a register value dependent on it’s TargetRegisterClass.

Basically, I find it confusing to have two integer indexes for the same value.

The registers themselves are part of a "register class". They may not start at 0 and may not be in order. For instance, target classes for control registers, floating point registers, etc. Look at the "*.inc" files in one of the back-ends for examples of how the TargetRegisterClass objects are created. They are in the build directory under lib/Target/X86/X86Gen*.inc (replace X86 with your favorite architecture).

-bw