Hi,
In the context of MachineCode custom inserter, I’m trying to enforce the mapping of virtual register to a physical one.
According to the documentation https://llvm.org/docs/CodeGenerator.html#mapping-virtual-registers-to-physical-registers
There are two ways: the direct one and the indirect ones. The indirect ones refer VirtRegMap class that I’ve never found. So I tried the direct one…
Mapping virtual registers to physical registers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There are two ways to map virtual registers to physical registers (or to memory
slots). The first way, that we will call direct mapping, is based on the use
of methods of the classes TargetRegisterInfo
, and MachineOperand
. The
second way, that we will call indirect mapping, relies on the VirtRegMap
class in order to insert loads and stores sending and getting values to and from
memory.
The direct mapping provides more flexibility to the developer of the register
allocator; however, it is more error prone, and demands more implementation
work. Basically, the programmer will have to specify where load and store
instructions should be inserted in the target function being compiled in order
to get and store values in memory. To assign a physical register to a virtual
register present in a given operand, use MachineOperand::setReg(p_reg)
. To
insert a store instruction, use TargetInstrInfo::storeRegToStackSlot(...)
,
and to insert a load instruction, use TargetInstrInfo::loadRegFromStackSlot
.
…
I tried the direct mapping as following:
MachineOperand destination = MI->getOperand(0);
MachineOperand offset = MI->getOperand(1);
unsigned destinationReg = destination.getReg();
int64_t FrameIndex = offset.getIndex();
destination.setReg(CLP::FA_ROFF0+FrameIndex);
destination.setIsDef(true);
TII->loadRegFromStackSlot(*MBB,
MI, destinationReg, FrameIndex,
&CLP::FPUaOffsetClassRegClass, TRI);
The code after customInserter seems valid but the compilation later hang-up in an infinite loop in procedure computeVirtRegs(); of pass LiveIntervals::runOnMachineFunction.
In other targets, I’ve seen an example with a setIsDef(true) for such physically mapped register. Is there something missing in my code (register other setting,…) ?