[PATCH] D128804: [greedyalloc] Return early when there is no register to allocate.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 04:31:49 PDT 2022


LuoYuanke created this revision.
Herald added subscribers: jsji, pengfei, hiraditya, qcolombet, MatzeB.
Herald added a project: All.
LuoYuanke requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In X86 we split greddy register allocation into 2 passes. The 1st pass
is to allocate tile register, and the 2nd pass is to allocate the rest
of virtual register. In most cases there is no tile register, so the 1st
pass is unnecessary. To improve the compiling time, we check if there is
any register need to be allocated by invoking callback
`ShouldAllocateClass`. If there is no register to be allocated, just
return false in the pass. This would improve the 1st greed RA pass for
normal cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128804

Files:
  llvm/lib/CodeGen/RegAllocGreedy.cpp


Index: llvm/lib/CodeGen/RegAllocGreedy.cpp
===================================================================
--- llvm/lib/CodeGen/RegAllocGreedy.cpp
+++ llvm/lib/CodeGen/RegAllocGreedy.cpp
@@ -2501,6 +2501,25 @@
   RegAllocBase::init(getAnalysis<VirtRegMap>(),
                      getAnalysis<LiveIntervals>(),
                      getAnalysis<LiveRegMatrix>());
+
+  bool HasVirtRegAlloc = false;
+  for (unsigned I = 0, E = MRI->getNumVirtRegs(); I != E; ++I) {
+    Register Reg = Register::index2VirtReg(I);
+    if (MRI->reg_nodbg_empty(Reg))
+      continue;
+    const TargetRegisterClass *RC = MRI->getRegClass(Reg);
+    if (!RC)
+      continue;
+    if (ShouldAllocateClass(*TRI, *RC)) {
+      HasVirtRegAlloc = true;
+      break;
+    }
+  }
+  // Early return if there is no virtual register to be allocated to a
+  // physical register.
+  if (!HasVirtRegAlloc)
+    return false;
+
   Indexes = &getAnalysis<SlotIndexes>();
   MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
   DomTree = &getAnalysis<MachineDominatorTree>();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128804.440937.patch
Type: text/x-patch
Size: 1050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/ff0bc2e5/attachment.bin>


More information about the llvm-commits mailing list