diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -142,6 +142,14 @@ /// Map generic virtual registers to their low-level type. VRegToTypeMap VRegToType; + /// Map a physical register into the virtual register it currently represents. + /// Useful for some target-hooks during the RegAllocFast to map a physical + /// register back to its virtual register. For instance, AMDGPU needs this + /// mapping inside the target spill hooks to identify the spills for certain + /// machine operands. This field is relevant only during RegAllocFast and will + /// be cleared elsewhere. + Register PhysToCurrentVirtReg; + /// Keep track of the physical registers that are live in to the function. /// Live in values are typically arguments in registers. LiveIn values are /// allowed to have virtual registers associated with them, stored in the @@ -769,6 +777,9 @@ /// type \p Ty. Register createGenericVirtualRegister(LLT Ty, StringRef Name = ""); + void setPhysToCurrentVirtReg(Register Reg) { PhysToCurrentVirtReg = Reg; } + Register getPhysToCurrentVirtReg() const { return PhysToCurrentVirtReg; } + /// Remove all types associated to virtual registers (after instruction /// selection and constraining of all generic virtual registers). void clearVirtRegTypes(); diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp b/llvm/lib/CodeGen/RegAllocFast.cpp --- a/llvm/lib/CodeGen/RegAllocFast.cpp +++ b/llvm/lib/CodeGen/RegAllocFast.cpp @@ -487,6 +487,8 @@ MCPhysReg PhysReg) { LLVM_DEBUG(dbgs() << "Reloading " << printReg(VirtReg, TRI) << " into " << printReg(PhysReg, TRI) << '\n'); + MRI->setPhysToCurrentVirtReg(VirtReg); + int FI = getStackSpaceFor(VirtReg); const TargetRegisterClass &RC = *MRI->getRegClass(VirtReg); TII->loadRegFromStackSlot(*MBB, Before, PhysReg, FI, &RC, TRI); @@ -707,6 +709,7 @@ assert(PhysReg != 0 && "Trying to assign no register"); LR.PhysReg = PhysReg; setPhysRegState(PhysReg, VirtReg); + MRI->setPhysToCurrentVirtReg(VirtReg); assignDanglingDebugValues(AtMI, VirtReg, PhysReg); } @@ -1600,6 +1603,9 @@ MRI->clearVirtRegs(); } + // Clear PhysToCurrentVirtReg. + MRI->setPhysToCurrentVirtReg(Register()); + StackSlotForVirtReg.clear(); LiveDbgValueMap.clear(); return true;