[PATCH] D138515: [CodeGen][RegAllocFast] Map PhysReg to its current VirtReg
Christudasan Devadasan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 23 09:47:48 PST 2022
cdevadas updated this revision to Diff 477539.
cdevadas edited the summary of this revision.
cdevadas added a comment.
PhysToCurrentVirtReg should also be updated while reloading a physical register from the spill location. It happens when a RegMask (for instance, a function call) clobbers a register that is used in an instruction later in the BB. Also, at a BB entry, the LiveIn registers are reloaded. The reload point begins a new live range and it should be properly reflected in the mapping.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138515/new/
https://reviews.llvm.org/D138515
Files:
llvm/include/llvm/CodeGen/MachineRegisterInfo.h
llvm/lib/CodeGen/RegAllocFast.cpp
Index: llvm/lib/CodeGen/RegAllocFast.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocFast.cpp
+++ 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;
Index: llvm/include/llvm/CodeGen/MachineRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ 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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138515.477539.patch
Type: text/x-patch
Size: 2536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221123/617894c1/attachment.bin>
More information about the llvm-commits
mailing list