[llvm] [GISel][RISCV]Implement indirect parameter passing (PR #95429)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 16 14:31:01 PDT 2024


================
@@ -790,6 +806,68 @@ bool CallLowering::handleAssignments(ValueHandler &Handler,
       CCValAssign &VA = ArgLocs[j + Idx];
       const ISD::ArgFlagsTy Flags = Args[i].Flags[Part];
 
+      // We found an indirect parameter passing, and we have an
+      // OutgoingValueHandler as our handler (so we are at the call site or the
+      // return value). In this case, start the construction of the following
+      // GMIR, that is responsible for the preparation of indirect parameter
+      // passing:
+      //
+      // %1(indirectly passed type) = The value to pass
+      // %3(pointer) = G_FRAME_INDEX %stack.0
+      // G_STORE %1, %3 :: (store (s128), align 8)
+      //
+      // After this GMIR, the remaining part of the loop body will decide how
+      // to get the value to the caller and we break out of the loop.
+      // NOTE: In the case, when the the pointer pointing to the value is passed
+      // in a register there is an exception to this, that is detailed bellow.
+      if (VA.getLocInfo() == CCValAssign::Indirect && Flags.isSplit() &&
+          !Handler.isIncomingArgumentHandler()) {
+        Align StackAlign = DL.getPrefTypeAlign(Args[i].Ty);
+        MachineFrameInfo &MFI = MF.getFrameInfo();
+        int FrameIdx = MFI.CreateStackObject(OrigTy.getScalarSizeInBits(),
+                                             StackAlign, false);
+
+        Register PointerToStackReg =
+            MIRBuilder.buildFrameIndex(PointerTy, FrameIdx).getReg(0);
+
+        MachinePointerInfo DstMPO;
+
+        Align FlagAlignment{};
+        if (Flags.isByVal()) {
+          FlagAlignment = Flags.getNonZeroByValAlign();
+        } else {
+          FlagAlignment = Flags.getNonZeroOrigAlign();
----------------
s-barannikov wrote:

`DataLayout::getStackAlignment` returns the _maximum_ alignment such that it does not cause stack realignment. It is intended for middle end optimizations.

For synthetic objects we can use any alignment as long as it does not cause hardware failures, but we would probably want accesses to this object to be fast. DL.getPreferredTypeAlign used when creating the object gives us exactly that fast alignment. There is no need to increase it because the only result it will give is holes in the stack.


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


More information about the llvm-commits mailing list