[llvm] [StackColoring] Change the StackColoring logic + enables it to handle spills (PR #143800)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 15:52:09 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/LiveStacks.h llvm/include/llvm/CodeGen/MachineFrameInfo.h llvm/include/llvm/CodeGen/MachineInstr.h llvm/lib/CodeGen/LiveStacks.cpp llvm/lib/CodeGen/MachineFrameInfo.cpp llvm/lib/CodeGen/MachineInstr.cpp llvm/lib/CodeGen/PrologEpilogInserter.cpp llvm/lib/CodeGen/StackColoring.cpp llvm/lib/CodeGen/StackSlotColoring.cpp llvm/lib/CodeGen/TargetPassConfig.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/CodeGen/LiveStacks.h b/llvm/include/llvm/CodeGen/LiveStacks.h
index 6b0b23bd7..e87f90c28 100644
--- a/llvm/include/llvm/CodeGen/LiveStacks.h
+++ b/llvm/include/llvm/CodeGen/LiveStacks.h
@@ -41,12 +41,12 @@ class LiveStacks {
   VNInfo::Allocator VNInfoAllocator;
 
   int StartIdx = -1;
-  SmallVector<LiveInterval*> S2LI;
+  SmallVector<LiveInterval *> S2LI;
   SmallVector<const TargetRegisterClass *> S2RC;
 
 public:
-  using iterator = SmallVector<LiveInterval*>::iterator;
-  using const_iterator = SmallVector<LiveInterval*>::const_iterator;
+  using iterator = SmallVector<LiveInterval *>::iterator;
+  using const_iterator = SmallVector<LiveInterval *>::const_iterator;
 
   const_iterator begin() const { return S2LI.begin(); }
   const_iterator end() const { return S2LI.end(); }
diff --git a/llvm/include/llvm/CodeGen/MachineFrameInfo.h b/llvm/include/llvm/CodeGen/MachineFrameInfo.h
index 8041b2829..fdb2fbd13 100644
--- a/llvm/include/llvm/CodeGen/MachineFrameInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineFrameInfo.h
@@ -123,7 +123,7 @@ public:
   static constexpr int NoUnderlyingSlot = std::numeric_limits<int>::min();
   static constexpr int IsUnderlyingSlot = std::numeric_limits<int>::min() + 1;
 
-  private:
+private:
   // Represent a single object allocated on the stack.
   struct StackObject {
     // The offset of this object from the stack pointer on entry to
@@ -542,7 +542,7 @@ public:
            "Invalid Object Idx!");
     assert(!isDeadObjectIndex(ObjectIdx) &&
            "Getting frame offset for a dead object?");
-    return Objects[ObjectIdx+NumFixedObjects].Offset;
+    return Objects[ObjectIdx + NumFixedObjects].Offset;
   }
 
   bool isObjectZExt(int ObjectIdx) const {
@@ -576,7 +576,7 @@ public:
            "Invalid Object Idx!");
     assert(!isDeadObjectIndex(ObjectIdx) &&
            "Setting frame offset for a dead object?");
-    Objects[ObjectIdx+NumFixedObjects].Offset = Offset;
+    Objects[ObjectIdx + NumFixedObjects].Offset = Offset;
   }
 
   SSPLayoutKind getObjectSSPLayout(int ObjectIdx) const {
diff --git a/llvm/lib/CodeGen/LiveStacks.cpp b/llvm/lib/CodeGen/LiveStacks.cpp
index 761c5a71f..ea158b2d9 100644
--- a/llvm/lib/CodeGen/LiveStacks.cpp
+++ b/llvm/lib/CodeGen/LiveStacks.cpp
@@ -56,7 +56,7 @@ LiveStacks::getOrCreateInterval(int Slot, const TargetRegisterClass *RC) {
   assert(Slot >= 0 && "Spill slot indice must be >= 0");
   if (StartIdx == -1)
     StartIdx = Slot;
-  
+
   int Idx = Slot - StartIdx;
   assert(Idx >= 0 && "Slot not in order ?");
   if (Idx < (int)S2LI.size()) {
diff --git a/llvm/lib/CodeGen/MachineFrameInfo.cpp b/llvm/lib/CodeGen/MachineFrameInfo.cpp
index 5b9974962..4e65f8949 100644
--- a/llvm/lib/CodeGen/MachineFrameInfo.cpp
+++ b/llvm/lib/CodeGen/MachineFrameInfo.cpp
@@ -13,7 +13,6 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 
 #include "llvm/ADT/BitVector.h"
-#include "llvm/IR/Instructions.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/TargetFrameLowering.h"
@@ -21,6 +20,7 @@
 #include "llvm/CodeGen/TargetRegisterInfo.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Config/llvm-config.h"
+#include "llvm/IR/Instructions.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
@@ -100,8 +100,7 @@ int MachineFrameInfo::CreateFixedObject(uint64_t Size, int64_t Offset,
   return -++NumFixedObjects;
 }
 
-int MachineFrameInfo::CreateFixedSpillStackObject(uint64_t Size,
-                                                  int64_t Offset,
+int MachineFrameInfo::CreateFixedSpillStackObject(uint64_t Size, int64_t Offset,
                                                   bool IsImmutable) {
   Align Alignment =
       commonAlignment(ForcedRealign ? Align(1) : StackAlignment, Offset);
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
index d006e3984..7a44b3937 100644
--- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
@@ -696,9 +696,9 @@ void PEIImpl::spillCalleeSavedRegs(MachineFunction &MF) {
 
 static inline void UpdateOffset(MachineFrameInfo &MFI, int FrameIdx,
                                 int64_t Offset) {
-    LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset
-                      << "]\n");
-    MFI.setObjectOffset(FrameIdx, Offset); // Set the computed offset
+  LLVM_DEBUG(dbgs() << "alloc FI(" << FrameIdx << ") at SP[" << Offset
+                    << "]\n");
+  MFI.setObjectOffset(FrameIdx, Offset); // Set the computed offset
 }
 
 /// AdjustStackOffset - Helper function used to adjust the stack frame offset.

``````````

</details>


https://github.com/llvm/llvm-project/pull/143800


More information about the llvm-commits mailing list