[PATCH] D43542: [CodeGen][FastRegAlloc] Disable registers spilling for a naked function (PR28641)

Konstantin Belochapka via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 18:22:24 PST 2018


kbelochapka created this revision.
kbelochapka added reviewers: stoklund, MatzeB.
Herald added a subscriber: qcolombet.

Problem:
Fast Registers Allocator can occasionally spill a register when processing a "naked" function.
It takes a input parameter register list and intersects it with a "asm" statement clobbered registers list, then it spills any register from a resulting list to a stack, which a "naked" function does not have.
Solution:  
Since a "naked" function can only have nothing but "asm" statements inside, and those "asm" statements can not have input or output parameters, it is safe to just disable any registers spilling for a "naked" function.


https://reviews.llvm.org/D43542

Files:
  lib/CodeGen/RegAllocFast.cpp


Index: lib/CodeGen/RegAllocFast.cpp
===================================================================
--- lib/CodeGen/RegAllocFast.cpp
+++ lib/CodeGen/RegAllocFast.cpp
@@ -317,6 +317,17 @@
   LiveReg &LR = *LRI;
   assert(PhysRegState[LR.PhysReg] == LRI->VirtReg && "Broken RegState mapping");
 
+  const BasicBlock *BB = MBB->getBasicBlock();
+  if (BB) {
+    const Function *F = BB->getParent();
+    if (F && F->hasFnAttribute(Attribute::Naked)) {
+      killVirtReg(LRI);
+      DEBUG(dbgs() << "Function is naked, disable register spilling "
+                   << printReg(LRI->VirtReg, TRI) << " in "
+                   << printReg(LR.PhysReg, TRI));
+      return;
+    }
+  }
   if (LR.Dirty) {
     // If this physreg is used by the instruction, we want to kill it on the
     // instruction, not on the spill.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43542.135184.patch
Type: text/x-patch
Size: 825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180221/4483534b/attachment.bin>


More information about the llvm-commits mailing list