[llvm] [RISCV] improve `musttail` support (PR #170547)

Folkert de Vries via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 3 15:55:26 PST 2025


================
@@ -115,6 +115,36 @@ bool TargetLowering::parametersInCSRMatch(const MachineRegisterInfo &MRI,
   return true;
 }
 
+SDValue TargetLowering::addTokenForArgument(SDValue Chain, SelectionDAG &DAG,
+                                            MachineFrameInfo &MFI,
+                                            int ClobberedFI) const {
+  SmallVector<SDValue, 8> ArgChains;
+  int64_t FirstByte = MFI.getObjectOffset(ClobberedFI);
+  int64_t LastByte = FirstByte + MFI.getObjectSize(ClobberedFI) - 1;
+
+  // Include the original chain at the beginning of the list. When this is
+  // used by target LowerCall hooks, this helps legalize find the
+  // CALLSEQ_BEGIN node.
+  ArgChains.push_back(Chain);
+
+  // Add a chain value for each stack argument corresponding
+  for (SDNode *U : DAG.getEntryNode().getNode()->users())
----------------
folkertdev wrote:

hmm I got confused then. The `addTokenForArgument` function is from 11 years ago (and I guess has worked OK over that period):

https://github.com/llvm/llvm-project/commit/09cc56431078f38ad2b992b50f316a51da643cb0

but I know that aarch64 support for tail calls with byval arguments improved in llvm 20 (https://godbolt.org/z/b5KbTPqzY), and I guess I got that mixed up with comments in the riscv tail call implementation saying it's based on the arm code.

---

Is there a way to still share code when following this suggestion? At least as I understand it it needs some additional bookkeeping on e.g. `RISCVMachineFunctionInfo` when processing arguments in `LowerFormalArguments`? 

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


More information about the llvm-commits mailing list