[PATCH] D134950: [CodeGen] Allow targets to define vreg flags

Christudasan Devadasan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 04:51:06 PDT 2022


cdevadas created this revision.
cdevadas added reviewers: qcolombet, MatzeB, stoklund, arsenm.
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.

This will help targets to define flags for virtual
registers involved in special operations and can use
them inside a target hook or somewhere at a later
point to customize the codegen decisions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134950

Files:
  llvm/include/llvm/CodeGen/MachineRegisterInfo.h
  llvm/lib/CodeGen/MachineRegisterInfo.cpp


Index: llvm/lib/CodeGen/MachineRegisterInfo.cpp
===================================================================
--- llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -46,6 +46,7 @@
   unsigned NumRegs = getTargetRegisterInfo()->getNumRegs();
   VRegInfo.reserve(256);
   RegAllocHints.reserve(256);
+  VRegFlags.reserve(256);
   UsedPhysRegMask.resize(NumRegs);
   PhysRegUseDefLists.reset(new MachineOperand*[NumRegs]());
 }
@@ -145,6 +146,7 @@
   Register Reg = Register::index2VirtReg(getNumVirtRegs());
   VRegInfo.grow(Reg);
   RegAllocHints.grow(Reg);
+  VRegFlags.grow(Reg);
   insertVRegByName(Name, Reg);
   return Reg;
 }
@@ -171,6 +173,7 @@
                                                    StringRef Name) {
   Register Reg = createIncompleteVirtualRegister(Name);
   VRegInfo[Reg].first = VRegInfo[VReg].first;
+  VRegFlags[Reg] = VRegFlags[VReg];
   setType(Reg, getType(VReg));
   if (TheDelegate)
     TheDelegate->MRI_NoteNewVirtualRegister(Reg);
@@ -182,6 +185,19 @@
   VRegToType[VReg] = Ty;
 }
 
+void MachineRegisterInfo::setFlag(Register Reg, uint8_t Flag) {
+  assert(Register::isVirtualRegister(Reg));
+  if (VRegFlags.inBounds(Reg))
+    VRegFlags[Reg] |= (uint8_t)1 << Flag;
+}
+
+bool MachineRegisterInfo::checkFlag(Register Reg, uint8_t Flag) const {
+  if (Register::isVirtualRegister(Reg))
+    return VRegFlags.inBounds(Reg) && VRegFlags[Reg] & ((uint8_t)1 << Flag);
+
+  return false;
+}
+
 Register
 MachineRegisterInfo::createGenericVirtualRegister(LLT Ty, StringRef Name) {
   // New virtual register number.
Index: llvm/include/llvm/CodeGen/MachineRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ llvm/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -137,6 +137,9 @@
   /// Map generic virtual registers to their low-level type.
   VRegToTypeMap VRegToType;
 
+  /// Target-specific flags associated with a virtual register.
+  IndexedMap<uint8_t, VirtReg2IndexFunctor> VRegFlags;
+
   /// 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
@@ -755,6 +758,12 @@
   /// type \p Ty.
   Register createGenericVirtualRegister(LLT Ty, StringRef Name = "");
 
+  /// Set \p Flag to \p Reg
+  void setFlag(Register Reg, uint8_t Flag);
+
+  /// Returns true if \p Flag is set for \p Reg
+  bool checkFlag(Register Reg, uint8_t Flag) const;
+
   /// 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: D134950.464218.patch
Type: text/x-patch
Size: 2752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220930/6be5b651/attachment.bin>


More information about the llvm-commits mailing list