[llvm] [GISel][RISCV]Implement indirect parameter passing (PR #95429)
Michael Maitland via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 17 10:50:11 PDT 2024
================
@@ -790,6 +805,41 @@ 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.
+ if (VA.getLocInfo() == CCValAssign::Indirect &&
+ !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 =
+ MachinePointerInfo::getFixedStack(MF, FrameIdx);
+
+ Align DstAlign =
+ std::max(DL.getStackAlignment(), inferAlignFromPtrInfo(MF, DstMPO));
+
+ MIRBuilder.buildStore(Args[i].OrigRegs[Part], PointerToStackReg, DstMPO,
+ DstAlign);
+
+ ArgReg = PointerToStackReg;
+ IndirectParameterPassingHandled = true;
+ }
+
if (VA.isMemLoc() && !Flags.isByVal()) {
----------------
michaelmaitland wrote:
Is it true that `!VA.isMemLoc` when we are handling an indirect parameter passing? I recall that you said it may have been the case [here](https://github.com/llvm/llvm-project/pull/95429#discussion_r1639481063).
If that is the case, can we do
```
Handler.assignValueToAddress(ArgReg, StackAddr, PointerTy, MPO, VA);
break;
```
on line 840 (inside the indirect block above) (and remove IndirectParameterPassingHandled)?
https://github.com/llvm/llvm-project/pull/95429
More information about the llvm-commits
mailing list