[PATCH] D48416: [StackSlotColoring] Fixed handling of StackID

Tim Renouf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 21 00:51:25 PDT 2018


tpr created this revision.
Herald added a subscriber: llvm-commits.

StackID is a property of a stack slot that allows a target to have
multiple spaces for spilling into. AMDGPU uses it to allow SGPRs to be
spilled into a VGPR, instead of using a real stack slot.

This commit fixes StackSlotColoring to ensure that two stack objects
with different StackID really don't share a slot, even if they are
colored out of order, and that the StackID gets set up in the colored
frame ids for later use.

Change-Id: I6a4d88ad7739d5d0550162b907e394b57fb3e437


Repository:
  rL LLVM

https://reviews.llvm.org/D48416

Files:
  lib/CodeGen/StackSlotColoring.cpp


Index: lib/CodeGen/StackSlotColoring.cpp
===================================================================
--- lib/CodeGen/StackSlotColoring.cpp
+++ lib/CodeGen/StackSlotColoring.cpp
@@ -79,6 +79,9 @@
     // OrigSizes - Sizess of stack objects before coloring.
     SmallVector<unsigned, 16> OrigSizes;
 
+    // OrigStackIDs - Identifier for stack memory type, before coloring.
+    SmallVector<uint8_t, 16> OrigStackIDs;
+
     // AllColors - If index is set, it's a spill slot, i.e. color.
     // FIXME: This assumes PEI locate spill slot with smaller indices
     // closest to stack pointer / frame pointer. Therefore, smaller
@@ -198,6 +201,7 @@
   int LastFI = MFI->getObjectIndexEnd();
   OrigAlignments.resize(LastFI);
   OrigSizes.resize(LastFI);
+  OrigStackIDs.resize(LastFI);
   AllColors.resize(LastFI);
   UsedColors.resize(LastFI);
   Assignments.resize(LastFI);
@@ -223,6 +227,7 @@
     SSIntervals.push_back(&li);
     OrigAlignments[FI] = MFI->getObjectAlignment(FI);
     OrigSizes[FI]      = MFI->getObjectSize(FI);
+    OrigStackIDs[FI]   = MFI->getStackID(FI);
     AllColors.set(FI);
   }
   DEBUG(dbgs() << '\n');
@@ -266,7 +271,7 @@
     }
   }
 
-  if (Color != -1 && MFI->getStackID(Color) != MFI->getStackID(FI)) {
+  if (Color != -1 && MFI->getStackID(Color) != OrigStackIDs[FI]) {
     DEBUG(dbgs() << "cannot share FIs with different stack IDs\n");
     Share = false;
   }
@@ -286,13 +291,14 @@
 
   // Change size and alignment of the allocated slot. If there are multiple
   // objects sharing the same slot, then make sure the size and alignment
-  // are large enough for all.
+  // are large enough for all. Also copy across the StackID.
   unsigned Align = OrigAlignments[FI];
   if (!Share || Align > MFI->getObjectAlignment(Color))
     MFI->setObjectAlignment(Color, Align);
   int64_t Size = OrigSizes[FI];
   if (!Share || Size > MFI->getObjectSize(Color))
     MFI->setObjectSize(Color, Size);
+  MFI->setStackID(Color, OrigStackIDs[FI]);
   return Color;
 }
 
@@ -493,6 +499,7 @@
   SSRefs.clear();
   OrigAlignments.clear();
   OrigSizes.clear();
+  OrigStackIDs.clear();
   AllColors.clear();
   UsedColors.clear();
   for (unsigned i = 0, e = Assignments.size(); i != e; ++i)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48416.152232.patch
Type: text/x-patch
Size: 2229 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180621/1660c3b0/attachment.bin>


More information about the llvm-commits mailing list