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

Gábor Spaits via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 02:00:30 PDT 2024


================
@@ -790,6 +804,32 @@ 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 are at the first part of
+      // the value being passed. In this case copy the incoming pointer into a
+      // virtual register so later we can load it.
+      if (VA.getLocInfo() == CCValAssign::Indirect && Flags.isSplit()) {
+        IndirectParameterPassingHandled = true;
+        if (Handler.isIncomingArgumentHandler()) {
+          Handler.assignValueToReg(ArgReg, VA.getLocReg(), VA);
+          Handler.assignValueToAddress(Args[i].OrigRegs[Part],
+                                       Args[i].Regs[Part], OrigTy,
+                                       MachinePointerInfo{}, VA);
+        } else {
+          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);
+          Handler.assignValueToAddress(Args[i].OrigRegs[Part],
+                                       PointerToStackReg, OrigTy,
+                                       MachinePointerInfo{}, VA);
+          Handler.assignValueToReg(PointerToStackReg, VA.getLocReg(), VA);
----------------
spaits wrote:

The inner loop that loop over the parts calls a `break;` in case of indirect passing, so we wont loop over all of the parts.

If all registers are used, then it is not an indirect parameter passing (example: when we have a 64 bit reg on rv32 then it is passed in two args not indirectly. In this case the if is not entered)

Yes I should check if the VA is register allocated.

Also maybe I should move this logic out of the loop, since  if we indirect passing then just the 0th element is "processed". 

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


More information about the llvm-commits mailing list