[llvm] [RISCV] Order stack objects by access density (PR #217507)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 01:50:01 PDT 2026


================
@@ -2846,6 +2848,75 @@ void RISCVFrameLowering::inlineStackProbe(MachineFunction &MF,
   }
 }
 
+namespace {
+/// Bookkeeping record used while ordering local stack objects by access
+/// density. One record is created for each frame index passed to
+/// orderFrameObjects().
+struct RISCVFrameSortingObject {
+  int ObjectIndex;
+  uint64_t ObjectSize;
+  Align ObjectAlign;
+  uint64_t NumUses = 0;
+};
+} // end anonymous namespace
+
+void RISCVFrameLowering::orderFrameObjects(
----------------
refuseno wrote:

Thanks for pointing this out. I checked the frame layout path.

Scalable RVV objects are already separated from this ordering: PEI only passes `TargetStackID::Default` objects to `orderFrameObjects()`, while `TargetStackID::ScalableVector` objects are laid out independently by `assignRVVStackObjectOffsets()`. So this sorting cannot mix the scalar/default stack region with the scalable RVV region.

Variable-sized objects can still appear here because they use the default StackID. X86 handles the same case by sorting them together with the other default-stack objects and using `4` as a proxy size when `ObjectSize == 0`. I've used the same value here.

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


More information about the llvm-commits mailing list