[PATCH] D138515: [CodeGen][RegAllocFast] Map PhysReg to its current VirtReg

Christudasan Devadasan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 22 11:05:34 PST 2022


cdevadas created this revision.
cdevadas added reviewers: qcolombet, arsenm, MatzeB, stoklund.
Herald added a subscriber: hiraditya.
Herald added a project: All.
cdevadas requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

It is unable to have the one-to-one mapping for a virtual
register and the physical register allocated for it during
fast regalloc. Due to the in-place allocation, a virtual
register, while having multiple live ranges, might get allocated
to different physical registers. This makes it impossible to
map the physical register back to its current live range
inside the target hooks, like the spill interface.

This patch introduces the physical register to the current
virtual register mapping whenever a physical register is
actually allocated.


Repository:
  rG LLVM Github Monorepo

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
@@ -707,6 +707,7 @@
   assert(PhysReg != 0 && "Trying to assign no register");
   LR.PhysReg = PhysReg;
   setPhysRegState(PhysReg, VirtReg);
+  MRI->setPhysToCurrentVirtReg(VirtReg);
 
   assignDanglingDebugValues(AtMI, VirtReg, PhysReg);
 }
@@ -1600,6 +1601,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.477256.patch
Type: text/x-patch
Size: 2123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221122/6ab23820/attachment.bin>


More information about the llvm-commits mailing list