On semantics of Reserved keyword for subregisters

I’m implementing code generator for in-house target. In this target there is a status register SR which consists of status bits representing different machine settings. This status bits are modeled as registers (subregisters of SR) and are marked as reserved. However, some bits of SR are used as binary registers which are used by logical instructions just like “ordinary” register.

Should SR be marked as a reserved register if it contains both reserved and unreserved parts?

You probably do not want to do this. There’s sometimes confusion between unallocatable and reserved registers. Status / flag registers generally should be unallocatable only, not reserved.

Yes, if one register is reserved, all aliasing registers should also be reserved (really we should track reservations on the regunit level)

Is that holds true even if status flags can be set by some instructions?

For instance, there are flags which enable/disable interrupts.

Yes. Flag registers are still trackable defs. Reserved is for cases where there are possible changes to the register that aren’t compiler visible. It’s more like volatile

1 Like

Where I can mark a reg as unallocatable?
While working with reserved regs, I’ve marked them via TargetRegisterInfo::getReservedRegs method.

There’s an isAllocatable field on the RegisterClass if the status register belongs to a class. Generally a flag register would just not belong to an allocatable class

1 Like